The dream journal's table (ADR 0038, D14): `dream`, in the sync engine's
database, a row a dream, its content sealed on the device (key ID,
payload, nonce), so the instance sees only that a dream exists, its size
and when it changed. The same rules as the sittings: the sync engine's
connector refuses a call without a session, each row lives in its
person's space, and deleting the person deletes their dreams with it
(the deletion test now writes and counts a dream too, and leaves
another person's).
The migration `20261103130213716-dreams`:
- `CREATE OR REPLACE FUNCTION gen_random_uuid_v7()`: the generator
repeats the UUID v7 function every migration; replacing it with the
same body changes nothing.
- `CREATE TABLE "dream"`: `id` a UUID v7 by default, `spaceId` the
person's sync space, `keyId` the key it is sealed with, `payload` the
sealed bytes (not null), `nonce` the sealing's nonce.
- `CREATE INDEX "dream_space_idx"` on `spaceId`, so deleting a space
finds its dreams without scanning the table.
- The foreign key from `spaceId` to `offline_sync_spaces("id")` with
`ON DELETE CASCADE`: deleting the space deletes its dreams.
- The version rows of every module in `serverpod_migrations`.
A new, empty table: nothing existing changes and no data moves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
587 lines
18 KiB
Dart
587 lines
18 KiB
Dart
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
|
|
/* To generate run: "serverpod generate" */
|
|
|
|
// ignore_for_file: implementation_imports
|
|
// ignore_for_file: library_private_types_in_public_api
|
|
// ignore_for_file: non_constant_identifier_names
|
|
// ignore_for_file: public_member_api_docs
|
|
// ignore_for_file: type_literal_in_constant_pattern
|
|
// ignore_for_file: use_super_parameters
|
|
// ignore_for_file: invalid_use_of_internal_member
|
|
// ignore_for_file: dead_code, unnecessary_type_check
|
|
|
|
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
|
import 'package:halkyon_base_server/halkyon_base_server.dart' as _ik8molhd;
|
|
import 'package:halkyon_oidc_server/halkyon_oidc_server.dart' as _ipoqfiqr;
|
|
import 'package:serverpod/protocol.dart' as _isp;
|
|
import 'package:serverpod/serverpod.dart' as _is;
|
|
import 'package:serverpod_auth_core_server/serverpod_auth_core_server.dart'
|
|
as _iacs;
|
|
import 'package:serverpod_auth_idp_server/serverpod_auth_idp_server.dart'
|
|
as _iais;
|
|
import 'package:serverpod_offline_sync_server/serverpod_offline_sync_server.dart'
|
|
as _izehhkf5;
|
|
import 'journal/dream.dart' as _is2va3v7;
|
|
import 'privacy/content_key.dart' as _imed3x5d;
|
|
import 'settings/meditate_settings.dart' as _iutacwgf;
|
|
import 'sitting/sitting.dart' as _ic8w2fbu;
|
|
export 'journal/dream.dart';
|
|
export 'privacy/content_key.dart';
|
|
export 'settings/meditate_settings.dart';
|
|
export 'sitting/sitting.dart';
|
|
export 'sync_tables.dart';
|
|
|
|
class Protocol extends _is.DatabaseSerializationManager {
|
|
Protocol._();
|
|
|
|
factory Protocol() => _instance;
|
|
|
|
static final Protocol _instance = Protocol._().._registerHostProtocols();
|
|
|
|
static List<_isp.TableDefinition> get targetTableDefinitions => [
|
|
_isp.TableDefinition(
|
|
name: 'content_key',
|
|
dartName: 'ContentKey',
|
|
schema: 'public',
|
|
module: 'halkyon_meditate',
|
|
columns: [
|
|
_isp.ColumnDefinition(
|
|
name: 'id',
|
|
columnType: _isp.ColumnType.uuid,
|
|
isNullable: false,
|
|
dartType: 'UuidValue?',
|
|
columnDefault: 'random_v7',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'spaceId',
|
|
columnType: _isp.ColumnType.bigint,
|
|
isNullable: true,
|
|
dartType: 'int?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'dataKeyId',
|
|
columnType: _isp.ColumnType.text,
|
|
isNullable: false,
|
|
dartType: 'String',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'sealedKey',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: false,
|
|
dartType: 'dart:typed_data:ByteData',
|
|
),
|
|
],
|
|
foreignKeys: [
|
|
_isp.ForeignKeyDefinition(
|
|
constraintName: 'content_key_fk_0',
|
|
columns: ['spaceId'],
|
|
referenceTable: 'offline_sync_spaces',
|
|
referenceTableSchema: 'public',
|
|
referenceColumns: ['id'],
|
|
onUpdate: _isp.ForeignKeyAction.noAction,
|
|
onDelete: _isp.ForeignKeyAction.cascade,
|
|
matchType: null,
|
|
),
|
|
],
|
|
indexes: [
|
|
_isp.IndexDefinition(
|
|
indexName: 'content_key_space_idx',
|
|
tableSpace: null,
|
|
elements: [
|
|
_isp.IndexElementDefinition(
|
|
type: _isp.IndexElementDefinitionType.column,
|
|
definition: 'spaceId',
|
|
),
|
|
],
|
|
type: 'btree',
|
|
isUnique: false,
|
|
isPrimary: false,
|
|
),
|
|
],
|
|
managed: true,
|
|
),
|
|
_isp.TableDefinition(
|
|
name: 'dream',
|
|
dartName: 'Dream',
|
|
schema: 'public',
|
|
module: 'halkyon_meditate',
|
|
columns: [
|
|
_isp.ColumnDefinition(
|
|
name: 'id',
|
|
columnType: _isp.ColumnType.uuid,
|
|
isNullable: false,
|
|
dartType: 'UuidValue?',
|
|
columnDefault: 'random_v7',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'spaceId',
|
|
columnType: _isp.ColumnType.bigint,
|
|
isNullable: true,
|
|
dartType: 'int?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'keyId',
|
|
columnType: _isp.ColumnType.text,
|
|
isNullable: true,
|
|
dartType: 'String?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'payload',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: false,
|
|
dartType: 'dart:typed_data:ByteData',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'nonce',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: true,
|
|
dartType: 'dart:typed_data:ByteData?',
|
|
),
|
|
],
|
|
foreignKeys: [
|
|
_isp.ForeignKeyDefinition(
|
|
constraintName: 'dream_fk_0',
|
|
columns: ['spaceId'],
|
|
referenceTable: 'offline_sync_spaces',
|
|
referenceTableSchema: 'public',
|
|
referenceColumns: ['id'],
|
|
onUpdate: _isp.ForeignKeyAction.noAction,
|
|
onDelete: _isp.ForeignKeyAction.cascade,
|
|
matchType: null,
|
|
),
|
|
],
|
|
indexes: [
|
|
_isp.IndexDefinition(
|
|
indexName: 'dream_space_idx',
|
|
tableSpace: null,
|
|
elements: [
|
|
_isp.IndexElementDefinition(
|
|
type: _isp.IndexElementDefinitionType.column,
|
|
definition: 'spaceId',
|
|
),
|
|
],
|
|
type: 'btree',
|
|
isUnique: false,
|
|
isPrimary: false,
|
|
),
|
|
],
|
|
managed: true,
|
|
),
|
|
_isp.TableDefinition(
|
|
name: 'meditate_settings',
|
|
dartName: 'MeditateSettings',
|
|
schema: 'public',
|
|
module: 'halkyon_meditate',
|
|
columns: [
|
|
_isp.ColumnDefinition(
|
|
name: 'id',
|
|
columnType: _isp.ColumnType.uuid,
|
|
isNullable: false,
|
|
dartType: 'UuidValue?',
|
|
columnDefault: 'random_v7',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'spaceId',
|
|
columnType: _isp.ColumnType.bigint,
|
|
isNullable: true,
|
|
dartType: 'int?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'keyId',
|
|
columnType: _isp.ColumnType.text,
|
|
isNullable: true,
|
|
dartType: 'String?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'payload',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: false,
|
|
dartType: 'dart:typed_data:ByteData',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'nonce',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: true,
|
|
dartType: 'dart:typed_data:ByteData?',
|
|
),
|
|
],
|
|
foreignKeys: [
|
|
_isp.ForeignKeyDefinition(
|
|
constraintName: 'meditate_settings_fk_0',
|
|
columns: ['spaceId'],
|
|
referenceTable: 'offline_sync_spaces',
|
|
referenceTableSchema: 'public',
|
|
referenceColumns: ['id'],
|
|
onUpdate: _isp.ForeignKeyAction.noAction,
|
|
onDelete: _isp.ForeignKeyAction.cascade,
|
|
matchType: null,
|
|
),
|
|
],
|
|
indexes: [
|
|
_isp.IndexDefinition(
|
|
indexName: 'meditate_settings_space_idx',
|
|
tableSpace: null,
|
|
elements: [
|
|
_isp.IndexElementDefinition(
|
|
type: _isp.IndexElementDefinitionType.column,
|
|
definition: 'spaceId',
|
|
),
|
|
],
|
|
type: 'btree',
|
|
isUnique: false,
|
|
isPrimary: false,
|
|
),
|
|
],
|
|
managed: true,
|
|
),
|
|
_isp.TableDefinition(
|
|
name: 'sitting',
|
|
dartName: 'Sitting',
|
|
schema: 'public',
|
|
module: 'halkyon_meditate',
|
|
columns: [
|
|
_isp.ColumnDefinition(
|
|
name: 'id',
|
|
columnType: _isp.ColumnType.uuid,
|
|
isNullable: false,
|
|
dartType: 'UuidValue?',
|
|
columnDefault: 'random_v7',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'spaceId',
|
|
columnType: _isp.ColumnType.bigint,
|
|
isNullable: true,
|
|
dartType: 'int?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'keyId',
|
|
columnType: _isp.ColumnType.text,
|
|
isNullable: true,
|
|
dartType: 'String?',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'payload',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: false,
|
|
dartType: 'dart:typed_data:ByteData',
|
|
),
|
|
_isp.ColumnDefinition(
|
|
name: 'nonce',
|
|
columnType: _isp.ColumnType.bytea,
|
|
isNullable: true,
|
|
dartType: 'dart:typed_data:ByteData?',
|
|
),
|
|
],
|
|
foreignKeys: [
|
|
_isp.ForeignKeyDefinition(
|
|
constraintName: 'sitting_fk_0',
|
|
columns: ['spaceId'],
|
|
referenceTable: 'offline_sync_spaces',
|
|
referenceTableSchema: 'public',
|
|
referenceColumns: ['id'],
|
|
onUpdate: _isp.ForeignKeyAction.noAction,
|
|
onDelete: _isp.ForeignKeyAction.cascade,
|
|
matchType: null,
|
|
),
|
|
],
|
|
indexes: [
|
|
_isp.IndexDefinition(
|
|
indexName: 'sitting_space_idx',
|
|
tableSpace: null,
|
|
elements: [
|
|
_isp.IndexElementDefinition(
|
|
type: _isp.IndexElementDefinitionType.column,
|
|
definition: 'spaceId',
|
|
),
|
|
],
|
|
type: 'btree',
|
|
isUnique: false,
|
|
isPrimary: false,
|
|
),
|
|
],
|
|
managed: true,
|
|
),
|
|
..._ik8molhd.Protocol.targetTableDefinitions,
|
|
..._iais.Protocol.targetTableDefinitions,
|
|
..._izehhkf5.Protocol.targetTableDefinitions,
|
|
..._ipoqfiqr.Protocol.targetTableDefinitions,
|
|
..._iacs.Protocol.targetTableDefinitions,
|
|
..._isp.Protocol.targetTableDefinitions,
|
|
];
|
|
|
|
static String? getClassNameFromObjectJson(dynamic data) {
|
|
if (data is! Map) return null;
|
|
final className = data['__className__'] as String?;
|
|
return className;
|
|
}
|
|
|
|
@override
|
|
T deserialize<T>(
|
|
dynamic data, [
|
|
Type? t,
|
|
]) {
|
|
t ??= T;
|
|
|
|
final dataClassName = getClassNameFromObjectJson(data);
|
|
if (dataClassName != null && dataClassName != getClassNameForType(t)) {
|
|
try {
|
|
return deserializeByClassName({
|
|
'className': dataClassName,
|
|
'data': data,
|
|
});
|
|
} on _is.DeserializationClassNameNotFoundException catch (_) {
|
|
// If the className is not recognized (e.g., older client receiving
|
|
// data with a new subtype), fall back to deserializing without the
|
|
// className, using the expected type T.
|
|
}
|
|
}
|
|
|
|
if (t == _is2va3v7.Dream) {
|
|
return _is2va3v7.Dream.fromJson(data) as T;
|
|
}
|
|
if (t == _imed3x5d.ContentKey) {
|
|
return _imed3x5d.ContentKey.fromJson(data) as T;
|
|
}
|
|
if (t == _iutacwgf.MeditateSettings) {
|
|
return _iutacwgf.MeditateSettings.fromJson(data) as T;
|
|
}
|
|
if (t == _ic8w2fbu.Sitting) {
|
|
return _ic8w2fbu.Sitting.fromJson(data) as T;
|
|
}
|
|
if (t == _is.getType<_is2va3v7.Dream?>()) {
|
|
return (data != null ? _is2va3v7.Dream.fromJson(data) : null) as T;
|
|
}
|
|
if (t == _is.getType<_imed3x5d.ContentKey?>()) {
|
|
return (data != null ? _imed3x5d.ContentKey.fromJson(data) : null) as T;
|
|
}
|
|
if (t == _is.getType<_iutacwgf.MeditateSettings?>()) {
|
|
return (data != null ? _iutacwgf.MeditateSettings.fromJson(data) : null)
|
|
as T;
|
|
}
|
|
if (t == _is.getType<_ic8w2fbu.Sitting?>()) {
|
|
return (data != null ? _ic8w2fbu.Sitting.fromJson(data) : null) as T;
|
|
}
|
|
try {
|
|
return _ik8molhd.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
try {
|
|
return _iais.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
try {
|
|
return _izehhkf5.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
try {
|
|
return _ipoqfiqr.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
try {
|
|
return _iacs.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
try {
|
|
return _isp.Protocol().deserialize<T>(data, t);
|
|
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
|
return super.deserialize<T>(data, t);
|
|
}
|
|
|
|
static String? getClassNameForType(Type type) {
|
|
return switch (type) {
|
|
_is2va3v7.Dream => 'Dream',
|
|
_imed3x5d.ContentKey => 'ContentKey',
|
|
_iutacwgf.MeditateSettings => 'MeditateSettings',
|
|
_ic8w2fbu.Sitting => 'Sitting',
|
|
_ => null,
|
|
};
|
|
}
|
|
|
|
@override
|
|
String? getClassNameForObject(Object? data) {
|
|
String? className = super.getClassNameForObject(data);
|
|
if (className != null) return className;
|
|
|
|
if (data is Map<String, dynamic> && data['__className__'] is String) {
|
|
return (data['__className__'] as String).replaceFirst(
|
|
'halkyon_meditate.',
|
|
'',
|
|
);
|
|
}
|
|
|
|
switch (data) {
|
|
case _is2va3v7.Dream():
|
|
return 'Dream';
|
|
case _imed3x5d.ContentKey():
|
|
return 'ContentKey';
|
|
case _iutacwgf.MeditateSettings():
|
|
return 'MeditateSettings';
|
|
case _ic8w2fbu.Sitting():
|
|
return 'Sitting';
|
|
}
|
|
className = _ik8molhd.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.') ? className : 'halkyon_base.$className';
|
|
}
|
|
className = _iais.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.')
|
|
? className
|
|
: 'serverpod_auth_idp.$className';
|
|
}
|
|
className = _izehhkf5.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.')
|
|
? className
|
|
: 'serverpod_offline_sync.$className';
|
|
}
|
|
className = _ipoqfiqr.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.') ? className : 'halkyon_oidc.$className';
|
|
}
|
|
className = _iacs.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.')
|
|
? className
|
|
: 'serverpod_auth_core.$className';
|
|
}
|
|
className = _isp.Protocol().getClassNameForObject(data);
|
|
if (className != null) {
|
|
return className.contains('.') ? className : 'serverpod.$className';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@override
|
|
dynamic deserializeByClassName(Map<String, dynamic> data) {
|
|
var dataClassName = data['className'];
|
|
if (dataClassName is! String) {
|
|
return super.deserializeByClassName(data);
|
|
}
|
|
if (dataClassName == 'Dream') {
|
|
return deserialize<_is2va3v7.Dream>(data['data']);
|
|
}
|
|
if (dataClassName == 'ContentKey') {
|
|
return deserialize<_imed3x5d.ContentKey>(data['data']);
|
|
}
|
|
if (dataClassName == 'MeditateSettings') {
|
|
return deserialize<_iutacwgf.MeditateSettings>(data['data']);
|
|
}
|
|
if (dataClassName == 'Sitting') {
|
|
return deserialize<_ic8w2fbu.Sitting>(data['data']);
|
|
}
|
|
if (dataClassName.startsWith('halkyon_base.')) {
|
|
data['className'] = dataClassName.substring(13);
|
|
return _ik8molhd.Protocol().deserializeByClassName(data);
|
|
}
|
|
if (dataClassName.startsWith('serverpod_auth_idp.')) {
|
|
data['className'] = dataClassName.substring(19);
|
|
return _iais.Protocol().deserializeByClassName(data);
|
|
}
|
|
if (dataClassName.startsWith('serverpod_offline_sync.')) {
|
|
data['className'] = dataClassName.substring(23);
|
|
return _izehhkf5.Protocol().deserializeByClassName(data);
|
|
}
|
|
if (dataClassName.startsWith('halkyon_oidc.')) {
|
|
data['className'] = dataClassName.substring(13);
|
|
return _ipoqfiqr.Protocol().deserializeByClassName(data);
|
|
}
|
|
if (dataClassName.startsWith('serverpod_auth_core.')) {
|
|
data['className'] = dataClassName.substring(20);
|
|
return _iacs.Protocol().deserializeByClassName(data);
|
|
}
|
|
if (dataClassName.startsWith('serverpod.')) {
|
|
data['className'] = dataClassName.substring(10);
|
|
return _isp.Protocol().deserializeByClassName(data);
|
|
}
|
|
return super.deserializeByClassName(data);
|
|
}
|
|
|
|
void _registerHostProtocols() {
|
|
_ik8molhd.Protocol().registerHostProtocol('halkyon_meditate', this);
|
|
_iais.Protocol().registerHostProtocol('halkyon_meditate', this);
|
|
_izehhkf5.Protocol().registerHostProtocol('halkyon_meditate', this);
|
|
_ipoqfiqr.Protocol().registerHostProtocol('halkyon_meditate', this);
|
|
_iacs.Protocol().registerHostProtocol('halkyon_meditate', this);
|
|
}
|
|
|
|
@override
|
|
_is.Table? getTableForType(Type t) {
|
|
{
|
|
var table = _ik8molhd.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
{
|
|
var table = _iais.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
{
|
|
var table = _izehhkf5.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
{
|
|
var table = _ipoqfiqr.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
{
|
|
var table = _iacs.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
{
|
|
var table = _isp.Protocol().getTableForType(t);
|
|
if (table != null) {
|
|
return table;
|
|
}
|
|
}
|
|
switch (t) {
|
|
case _is2va3v7.Dream:
|
|
return _is2va3v7.Dream.t;
|
|
case _imed3x5d.ContentKey:
|
|
return _imed3x5d.ContentKey.t;
|
|
case _iutacwgf.MeditateSettings:
|
|
return _iutacwgf.MeditateSettings.t;
|
|
case _ic8w2fbu.Sitting:
|
|
return _ic8w2fbu.Sitting.t;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@override
|
|
List<_isp.TableDefinition> getTargetTableDefinitions() =>
|
|
targetTableDefinitions;
|
|
|
|
@override
|
|
String getModuleName() => 'halkyon_meditate';
|
|
|
|
/// Maps any `Record`s known to this [Protocol] to their JSON representation
|
|
///
|
|
/// Throws in case the record type is not known.
|
|
///
|
|
/// This method will return `null` (only) for `null` inputs.
|
|
Map<String, dynamic>? mapRecordToJson(Record? record) {
|
|
if (record == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
return _ik8molhd.Protocol().mapRecordToJson(record);
|
|
} catch (_) {}
|
|
try {
|
|
return _iais.Protocol().mapRecordToJson(record);
|
|
} catch (_) {}
|
|
try {
|
|
return _izehhkf5.Protocol().mapRecordToJson(record);
|
|
} catch (_) {}
|
|
try {
|
|
return _ipoqfiqr.Protocol().mapRecordToJson(record);
|
|
} catch (_) {}
|
|
try {
|
|
return _iacs.Protocol().mapRecordToJson(record);
|
|
} catch (_) {}
|
|
throw Exception('Unsupported record type ${record.runtimeType}');
|
|
}
|
|
}
|