utopicnarwhal / pocketbase_utils

Dart package that creates a binding between your pocketbase server and your Flutter app by generating typesafe boilerplate code of your collections from `pb_schema.json` file.
Apache License 2.0
3 stars 0 forks source link

Feature request: Publishing the field types would be useful #1

Closed DavBfr closed 7 months ago

DavBfr commented 9 months ago

You already have an enum and parse it for generating the dart type. A map with the field and the pocketbase field type can be useful for generating UI fields automatically on the client side.

utopicnarwhal commented 9 months ago

for generating UI fields automatically on the client side.

What do you use to generate them?

DavBfr commented 9 months ago

yet, just exploring pocketbase for now. I have extensions to get a stream of records instead of event-based listeners. Some sort of partially automatic UI would be neat. It would need all the field and collection information provided by the JSON export, as constants somehow.

DavBfr commented 9 months ago

Something like that:


enum FieldType {
  text,
  editor,
  number,
  bool,
  email,
  url,
  date,
  select,
  relation,
  file,
  json,
}

class Field {
  const Field({
    required this.system,
    required this.id,
    required this.name,
    required this.type,
    required this.required,
    required this.presentable,
    required this.unique,
    this.min,
    this.max,
    this.pattern,
    this.values,
    this.maxSelect,
    this.exceptDomains,
    this.onlyDomains,
  });

  final bool system;
  final String id;
  final String name;
  final FieldType type;
  final bool required;
  final bool presentable;
  final bool unique;
  final List<String>? values;
  final int? maxSelect;
  final int? min;
  final int? max;
  final String? pattern;
  final String? exceptDomains;
  final String? onlyDomains;
}

enum CollectionType { base, auth }

typedef MakeRecord<T extends BaseRecord> = T Function(RecordModel recordModel);

class Collection<T extends BaseRecord> {
  const Collection({
    required this.id,
    required this.name,
    required this.type,
    required this.system,
    required this.schema,
    this.indexes = const [],
    this.listRule,
    this.viewRule,
    this.createRule,
    this.updateRule,
    this.deleteRule,
    required this.makeRecord,
  });

  final String id;
  final String name;
  final CollectionType type;
  final bool system;
  final List<Field> schema;
  final List<String> indexes;
  final String? listRule;
  final String? viewRule;
  final String? createRule;
  final String? updateRule;
  final String? deleteRule;
  final MakeRecord<T> makeRecord;
}
utopicnarwhal commented 9 months ago

In that case, in theory, you can just add the package as a dependency and use the classes that I've created in the lib/schema folder to parse and generate the fields that you need