rimecms 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/adapter-sqlite/read.server.js +4 -4
  2. package/dist/adapter-sqlite/table.server.d.ts +3 -6
  3. package/dist/adapter-sqlite/table.server.js +3 -6
  4. package/dist/adapter-sqlite/transform.server.d.ts +1 -1
  5. package/dist/adapter-sqlite/transform.server.js +3 -2
  6. package/dist/adapter-sqlite/write.server.d.ts +13 -15
  7. package/dist/adapter-sqlite/write.server.js +15 -17
  8. package/dist/core/adapter.d.ts +19 -33
  9. package/dist/core/adapter.js +0 -12
  10. package/dist/core/auth/augment.js +2 -1
  11. package/dist/core/auth/hooks/augment-fields-password.server.d.ts +2 -2
  12. package/dist/core/auth/hooks/augment-fields-password.server.js +2 -2
  13. package/dist/core/auth/tables.d.ts +2 -5
  14. package/dist/core/auth/tables.js +3 -7
  15. package/dist/core/auth/validate-config.d.ts +3 -8
  16. package/dist/core/auth/validate-config.js +4 -10
  17. package/dist/core/config/types.d.ts +6 -6
  18. package/dist/core/config/validate.server.js +11 -0
  19. package/dist/core/fields/builders/boolean-builder.d.ts +2 -2
  20. package/dist/core/fields/builders/boolean-builder.js +4 -1
  21. package/dist/core/fields/builders/select-builder.d.ts +3 -3
  22. package/dist/core/fields/builders/select-builder.js +4 -2
  23. package/dist/core/fields/complete.d.ts +18 -0
  24. package/dist/core/fields/complete.js +32 -0
  25. package/dist/core/fields/empty.d.ts +14 -0
  26. package/dist/core/fields/empty.js +13 -0
  27. package/dist/core/fields/initial.d.ts +32 -0
  28. package/dist/core/fields/initial.js +47 -0
  29. package/dist/core/fields/util.d.ts +0 -16
  30. package/dist/core/fields/util.js +0 -29
  31. package/dist/core/pipeline/build-document.server.d.ts +4 -10
  32. package/dist/core/pipeline/build-document.server.js +8 -17
  33. package/dist/core/pipeline/hooks/data-config-map.server.d.ts +1 -1
  34. package/dist/core/pipeline/hooks/data-config-map.server.js +1 -1
  35. package/dist/core/pipeline/hooks/process-document-fields.server.d.ts +3 -2
  36. package/dist/core/pipeline/hooks/process-document-fields.server.js +3 -16
  37. package/dist/core/pipeline/hooks/set-default-values.server.d.ts +15 -4
  38. package/dist/core/pipeline/hooks/set-default-values.server.js +50 -25
  39. package/dist/core/pipeline/hooks/validate-fields.server.js +1 -1
  40. package/dist/core/pipeline/run.server.js +1 -2
  41. package/dist/core/prototype/area/api.server.d.ts +4 -6
  42. package/dist/core/prototype/area/api.server.js +4 -6
  43. package/dist/core/prototype/area/definition.server.js +23 -9
  44. package/dist/core/prototype/area/hooks.server.js +1 -1
  45. package/dist/core/prototype/collection/api.server.d.ts +5 -6
  46. package/dist/core/prototype/collection/api.server.js +5 -6
  47. package/dist/core/prototype/collection/definition.js +3 -8
  48. package/dist/core/prototype/collection/hooks/merge-with-initial.server.d.ts +15 -0
  49. package/dist/core/prototype/collection/hooks/merge-with-initial.server.js +20 -0
  50. package/dist/core/prototype/collection/hooks.server.js +5 -5
  51. package/dist/core/prototype/collection/nested/module.js +1 -1
  52. package/dist/core/prototype/collection/nested/module.server.js +1 -1
  53. package/dist/core/prototype/collection/operations/duplicate.js +4 -8
  54. package/dist/core/prototype/collection/upload/directories/derive.js +2 -2
  55. package/dist/core/prototype/collection/upload/hooks/handle-path-creation.server.js +2 -2
  56. package/dist/core/prototype/define.d.ts +2 -2
  57. package/dist/core/prototype/define.js +4 -4
  58. package/dist/core/prototype/initial.d.ts +23 -0
  59. package/dist/core/prototype/initial.js +19 -0
  60. package/dist/core/prototype/shared/versions/augment.d.ts +2 -4
  61. package/dist/core/prototype/shared/versions/augment.js +4 -6
  62. package/dist/core/prototype/shared/versions/configure.server.js +3 -3
  63. package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.d.ts +14 -2
  64. package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.js +28 -22
  65. package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +3 -4
  66. package/dist/core/prototype/shared/versions/{blank.d.ts → initial.d.ts} +2 -4
  67. package/dist/core/prototype/shared/versions/{blank.js → initial.js} +2 -4
  68. package/dist/core/prototype/when.d.ts +2 -6
  69. package/dist/core/prototype/when.js +2 -6
  70. package/dist/fields/blocks/component/AddBlockButton.svelte +2 -2
  71. package/dist/fields/blocks/component/focus/BlocksFocus.svelte +2 -13
  72. package/dist/fields/blocks/component/focus/Inspector.svelte +43 -3
  73. package/dist/fields/blocks/component/focus/Renders.svelte +29 -1
  74. package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +24 -4
  75. package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +6 -1
  76. package/dist/fields/blocks/component/focus/focus.svelte.d.ts +11 -3
  77. package/dist/fields/blocks/component/focus/focus.svelte.js +31 -10
  78. package/dist/fields/blocks/defaults.d.ts +22 -0
  79. package/dist/fields/blocks/defaults.js +23 -0
  80. package/dist/fields/blocks/index.d.ts +18 -2
  81. package/dist/fields/blocks/index.js +30 -0
  82. package/dist/fields/combobox/index.d.ts +2 -2
  83. package/dist/fields/combobox/index.js +2 -1
  84. package/dist/fields/date/index.d.ts +2 -2
  85. package/dist/fields/date/index.js +2 -1
  86. package/dist/fields/email/index.d.ts +2 -2
  87. package/dist/fields/email/index.js +2 -1
  88. package/dist/fields/group/index.d.ts +1 -0
  89. package/dist/fields/link/index.d.ts +3 -2
  90. package/dist/fields/link/index.js +2 -1
  91. package/dist/fields/number/index.d.ts +3 -2
  92. package/dist/fields/number/index.js +2 -1
  93. package/dist/fields/relation/component/default/Default.svelte +1 -1
  94. package/dist/fields/relation/component/upload/Create.svelte +1 -1
  95. package/dist/fields/relation/index.d.ts +2 -2
  96. package/dist/fields/relation/index.js +2 -1
  97. package/dist/fields/rich-text/index.d.ts +2 -2
  98. package/dist/fields/rich-text/index.js +2 -1
  99. package/dist/fields/slug/index.d.ts +3 -2
  100. package/dist/fields/slug/index.js +2 -1
  101. package/dist/fields/text/index.d.ts +3 -2
  102. package/dist/fields/text/index.js +2 -1
  103. package/dist/fields/textarea/index.d.ts +3 -2
  104. package/dist/fields/textarea/index.js +2 -1
  105. package/dist/fields/time/index.d.ts +2 -2
  106. package/dist/fields/time/index.js +2 -1
  107. package/dist/fields/toggle/index.d.ts +3 -2
  108. package/dist/fields/toggle/index.js +2 -2
  109. package/dist/fields/tree/component/AddItemButton.svelte +3 -4
  110. package/dist/fields/tree/component/AddItemButton.svelte.d.ts +1 -1
  111. package/dist/fields/tree/defaults.d.ts +21 -0
  112. package/dist/fields/tree/defaults.js +18 -0
  113. package/dist/fields/tree/index.d.ts +17 -3
  114. package/dist/fields/tree/index.js +27 -0
  115. package/dist/fields/types.d.ts +14 -0
  116. package/dist/panel/context/blocks-ops.d.ts +0 -1
  117. package/dist/panel/context/blocks-ops.js +1 -2
  118. package/dist/panel/pages/collection-document/load.server.js +1 -1
  119. package/dist/util/object.d.ts +2 -2
  120. package/dist/util/object.js +3 -3
  121. package/dist/util/random.d.ts +2 -0
  122. package/dist/util/random.js +2 -0
  123. package/package.json +1 -1
  124. package/dist/core/fields/blank.d.ts +0 -21
  125. package/dist/core/fields/blank.js +0 -37
  126. package/dist/core/prototype/blank.d.ts +0 -26
  127. package/dist/core/prototype/blank.js +0 -22
  128. package/dist/core/prototype/collection/hooks/merge-with-blank.server.d.ts +0 -9
  129. package/dist/core/prototype/collection/hooks/merge-with-blank.server.js +0 -14
@@ -61,11 +61,11 @@ export const readPrototype = async ({ db, tables, configCtx }, { slug, id, selec
61
61
  }),
62
62
  // The row the caller's filter names, else the newest — one query either way, and the
63
63
  // adapter chooses nothing. Which content row a request means is decided above this module
64
- // and arrives as an ordinary filter (`FeatureDefinition.readQuery`).
64
+ // and arrives as an ordinary filter (`versionsReadQuery`).
65
65
  //
66
- // The `orderBy`/`limit` are not the third branch coming back: they are what "the content
67
- // of this document" means with nothing else said, the same statement as `updatedAt` being
68
- // the default sort. A filter narrows within that, it does not replace it.
66
+ // The `orderBy`/`limit` are what "the content of this document" means with nothing else
67
+ // said, the same statement as `updatedAt` being the default sort. A filter narrows within
68
+ // that, it does not replace it.
69
69
  ...(content
70
70
  ? {
71
71
  where: {
@@ -2,15 +2,12 @@ import type { TableHandle } from '../core/adapter.js';
2
2
  import type { GetRegisterType } from '../index.js';
3
3
  import type { SqliteDatabase } from './types.server.js';
4
4
  /**
5
- * Handles for the tables features declared — see `FeatureDefinition.tables`.
5
+ * Handles for the tables a config declares in `$tables`, the ones no prototype owns: better-auth's
6
+ * users, sessions and accounts (`core/auth/configure.ts`).
6
7
  *
7
8
  * The counterpart to `prototype.server.ts`, and much smaller for one reason: a declared table has
8
9
  * no config behind it. Nothing to resolve a path against, no locales branch, no children, no
9
- * blank to merge. So the filter is a flat column-to-value map and the verbs are three.
10
- *
11
- * This is what let `AuthHandle` collapse to Better-auth's own adapter. Its last three methods
12
- * read and wrote `auth_users`, `auth_sessions` and `auth_accounts` — real tables that core simply
13
- * had no way to name until a feature could declare one.
10
+ * empty fields to add. So the filter is a flat column-to-value map and the verbs are three.
14
11
  */
15
12
  export declare const createTableHandles: (args: {
16
13
  db: SqliteDatabase;
@@ -2,15 +2,12 @@ import { RimeError } from '../core/errors/index.js';
2
2
  import { and, eq } from 'drizzle-orm';
3
3
  import { declaredTableProperty } from './naming.server.js';
4
4
  /**
5
- * Handles for the tables features declared — see `FeatureDefinition.tables`.
5
+ * Handles for the tables a config declares in `$tables`, the ones no prototype owns: better-auth's
6
+ * users, sessions and accounts (`core/auth/configure.ts`).
6
7
  *
7
8
  * The counterpart to `prototype.server.ts`, and much smaller for one reason: a declared table has
8
9
  * no config behind it. Nothing to resolve a path against, no locales branch, no children, no
9
- * blank to merge. So the filter is a flat column-to-value map and the verbs are three.
10
- *
11
- * This is what let `AuthHandle` collapse to Better-auth's own adapter. Its last three methods
12
- * read and wrote `auth_users`, `auth_sessions` and `auth_accounts` — real tables that core simply
13
- * had no way to name until a feature could declare one.
10
+ * empty fields to add. So the filter is a flat column-to-value map and the verbs are three.
14
11
  */
15
12
  export const createTableHandles = (args) => {
16
13
  const { db, tables } = args;
@@ -6,7 +6,7 @@ import type { ConfigContext } from '../core/rime.server.js';
6
6
  * Turns the rows a read returned into the four piles core builds a document from.
7
7
  *
8
8
  * Everything here needs `tables`: which children hang off this document, which locales branch
9
- * belongs to which row, which columns a branch has. Everything that did not — the blank merge,
9
+ * belongs to which row, which columns a branch has. Everything that does not — the empty fields,
10
10
  * the key stripping, the relation assembly, the depth walk — is in
11
11
  * `core/pipeline/build-document.server.ts`.
12
12
  */
@@ -11,7 +11,7 @@ import { resolvedReferencesOf } from '../core/fields/util.js';
11
11
  * Turns the rows a read returned into the four piles core builds a document from.
12
12
  *
13
13
  * Everything here needs `tables`: which children hang off this document, which locales branch
14
- * belongs to which row, which columns a branch has. Everything that did not — the blank merge,
14
+ * belongs to which row, which columns a branch has. Everything that does not — the empty fields,
15
15
  * the key stripping, the relation assembly, the depth walk — is in
16
16
  * `core/pipeline/build-document.server.ts`.
17
17
  */
@@ -21,7 +21,8 @@ export const createTransformHandle = (args) => {
21
21
  * Merges a child row's locales branch onto it — the rows the read returned, one per locale in
22
22
  * the fallback order, each column from the first that holds it — and nulls the localized
23
23
  * columns no locale has saved yet: a localized block fetched in a locale it was never written
24
- * in reads as absent columns otherwise, and absent is not null once the blank is merged.
24
+ * in reads as absent columns otherwise: the empty fields a read adds stop at the list, and never
25
+ * reach into a block.
25
26
  */
26
27
  const withLocalesBranch = (row, branchTable, order) => {
27
28
  const merged = {
@@ -53,13 +53,9 @@ type Deps = {
53
53
  tables: Dic;
54
54
  };
55
55
  /**
56
- * Writes the rows the caller's plan names.
57
- *
58
- * Three branches until 1ec2dfca's successor, decoded here from an enum the caller passed down.
59
- * They differed in exactly two facts — is there a second row, and has somebody already written it
60
- * — and both are settled before the call now (`core/pipeline/run.server.ts` builds the plan,
61
- * `FeatureDefinition.writePlan` refines it). What was left is the same two writes in every case,
62
- * so there is one path.
56
+ * Writes the rows the caller's plan names, one path for every case. Whether there is a second row,
57
+ * and whether it is already written, is settled before the call: `core/pipeline/run.server.ts`
58
+ * builds the plan and `versionsWritePlan` refines it.
63
59
  *
64
60
  * The content row's *table* is still the adapter's to know: registration carries the versions table, and
65
61
  * where rows live is storage. Which row, and whether to touch it, is the caller's.
@@ -127,11 +123,14 @@ export declare const deletePrototype: ({ db, tables }: Deps, { slug, id }: {
127
123
  /**
128
124
  * Brings a singleton's row into being if it is not already there. Boot only.
129
125
  *
130
- * Deliberately not an `insert`: it takes no data beyond the blank document, hands back no id,
131
- * and a second call does nothing. That shape is what lets a singleton have no create at all
132
- * while its one row still comes from somewhere.
126
+ * Deliberately not an `insert`: it takes no data beyond the initial document, and a second call
127
+ * does nothing. That shape is what lets a singleton have no create at all while its one row still
128
+ * comes from somewhere. It answers the row the document's children hang off when it wrote one,
129
+ * `null` when the row was there.
133
130
  */
134
- export declare const ensurePrototypeExists: ({ db, tables }: Deps, { slug, blank, locale, versions }: EnsureExistsArgs) => Promise<void>;
131
+ export declare const ensurePrototypeExists: ({ db, tables }: Deps, { slug, initial, locale, versions }: EnsureExistsArgs) => Promise<{
132
+ contentId: string;
133
+ } | null>;
135
134
  type InsertArgs = {
136
135
  versions?: VersionsTable;
137
136
  slug: string;
@@ -146,11 +145,10 @@ type EnsureExistsArgs = {
146
145
  versions?: VersionsTable;
147
146
  slug: string;
148
147
  /**
149
- * The document to write. Already shaped by whatever the prototype's features say a bootstrapped
150
- * first document carries — see `FeatureDefinition.blank` with intent `'seed'`. This module
151
- * writes it and asks nothing about what is in it.
148
+ * The document to write, already shaped as a first document: `initialVersion` publishes it when
149
+ * the prototype has drafts. This module writes it and asks nothing about what is in it.
152
150
  */
153
- blank: Dic;
151
+ initial: Dic;
154
152
  locale?: string;
155
153
  };
156
154
  /**
@@ -45,13 +45,9 @@ export const insertRowWithLocales = async ({ db, tables }, args) => {
45
45
  return id;
46
46
  };
47
47
  /**
48
- * Writes the rows the caller's plan names.
49
- *
50
- * Three branches until 1ec2dfca's successor, decoded here from an enum the caller passed down.
51
- * They differed in exactly two facts — is there a second row, and has somebody already written it
52
- * — and both are settled before the call now (`core/pipeline/run.server.ts` builds the plan,
53
- * `FeatureDefinition.writePlan` refines it). What was left is the same two writes in every case,
54
- * so there is one path.
48
+ * Writes the rows the caller's plan names, one path for every case. Whether there is a second row,
49
+ * and whether it is already written, is settled before the call: `core/pipeline/run.server.ts`
50
+ * builds the plan and `versionsWritePlan` refines it.
55
51
  *
56
52
  * The content row's *table* is still the adapter's to know: registration carries the versions table, and
57
53
  * where rows live is storage. Which row, and whether to touch it, is the caller's.
@@ -224,15 +220,16 @@ export const deletePrototype = async ({ db, tables }, { slug, id }) => {
224
220
  /**
225
221
  * Brings a singleton's row into being if it is not already there. Boot only.
226
222
  *
227
- * Deliberately not an `insert`: it takes no data beyond the blank document, hands back no id,
228
- * and a second call does nothing. That shape is what lets a singleton have no create at all
229
- * while its one row still comes from somewhere.
223
+ * Deliberately not an `insert`: it takes no data beyond the initial document, and a second call
224
+ * does nothing. That shape is what lets a singleton have no create at all while its one row still
225
+ * comes from somewhere. It answers the row the document's children hang off when it wrote one,
226
+ * `null` when the row was there.
230
227
  */
231
- export const ensurePrototypeExists = async ({ db, tables }, { slug, blank, locale, versions }) => {
228
+ export const ensurePrototypeExists = async ({ db, tables }, { slug, initial, locale, versions }) => {
232
229
  const table = baseTableName(slug);
233
230
  const [existing] = await db.select({ id: tables[table].id }).from(tables[table]);
234
231
  if (existing)
235
- return;
232
+ return null;
236
233
  const now = new Date();
237
234
  if (versions) {
238
235
  const docId = await adapterUtil.insertTableRecord(db, tables, table, {
@@ -240,33 +237,34 @@ export const ensurePrototypeExists = async ({ db, tables }, { slug, blank, local
240
237
  updatedAt: now
241
238
  });
242
239
  const contentTable = baseTableName(versions.slug);
243
- const { mainData, localizedData, isLocalized } = adapterUtil.prepareSchemaData(blank, {
240
+ const { mainData, localizedData, isLocalized } = adapterUtil.prepareSchemaData(initial, {
244
241
  tables,
245
242
  mainTableName: contentTable,
246
243
  localesTableName: tableName({ owner: contentTable, branch: 'locales' }),
247
244
  locale,
248
245
  fillNotNull: true
249
246
  });
250
- await insertRowWithLocales({ db, tables }, {
247
+ const contentId = await insertRowWithLocales({ db, tables }, {
251
248
  table: contentTable,
252
249
  row: { ownerId: docId, ...mainData },
253
250
  now,
254
251
  localized: { data: localizedData, isLocalized, locale }
255
252
  });
256
- return;
253
+ return { contentId };
257
254
  }
258
255
  const localesTable = tableName({ owner: table, branch: 'locales' });
259
- const { mainData, localizedData, isLocalized } = adapterUtil.prepareSchemaData(blank, {
256
+ const { mainData, localizedData, isLocalized } = adapterUtil.prepareSchemaData(initial, {
260
257
  tables,
261
258
  mainTableName: table,
262
259
  localesTableName: localesTable,
263
260
  locale,
264
261
  fillNotNull: true
265
262
  });
266
- await insertRowWithLocales({ db, tables }, {
263
+ const contentId = await insertRowWithLocales({ db, tables }, {
267
264
  table,
268
265
  row: mainData,
269
266
  now,
270
267
  localized: { data: localizedData, isLocalized, locale }
271
268
  });
269
+ return { contentId };
272
270
  };
@@ -47,7 +47,7 @@ export interface Adapter {
47
47
  * The handle for a table a feature declared — see `TableDeclaration`.
48
48
  *
49
49
  * Separate from the two above because a declared table is not a prototype: no fields, no
50
- * pipeline, no access rules, nothing to merge a blank into. Three verbs and a flat filter,
50
+ * pipeline, no access rules, no empty fields to add. Three verbs and a flat filter,
51
51
  * because whoever declared it already knows its columns and there is nothing to resolve
52
52
  * against a config.
53
53
  */
@@ -215,11 +215,16 @@ export interface AreaHandle extends BaseHandle {
215
215
  }): Promise<{
216
216
  id: string;
217
217
  }>;
218
- /** Boot only. Writes the row if absent; a no-op if not. */
218
+ /**
219
+ * Boot only. Writes the row if absent, and answers the row its children hang off — the version
220
+ * row when there is one. `null`, and nothing written, when the row was there.
221
+ */
219
222
  ensureExists(args: {
220
- blank: Dic;
223
+ initial: Dic;
221
224
  locale?: string;
222
- }): Promise<void>;
225
+ }): Promise<{
226
+ contentId: string;
227
+ } | null>;
223
228
  }
224
229
  /**
225
230
  * `parentSlug` is the slug that owns the children — the prototype's versions when it has one, the
@@ -380,9 +385,9 @@ export interface TransformHandle {
380
385
  * Three things, and each of them needs a table: resolving which tables hang off this document,
381
386
  * merging each locales branch, and turning column names back into document paths.
382
387
  *
383
- * `buildDocument` in `core/pipeline/build-document.server.ts` takes it from here — merging the
384
- * blank, keeping the bookkeeping the caller asked for, and assembling relations into document
385
- * properties are core's, and none of them needs a table.
388
+ * `buildDocument` in `core/pipeline/build-document.server.ts` takes it from here — adding the
389
+ * empty fields, keeping the bookkeeping the caller asked for, and assembling relations into
390
+ * document properties are core's, and none of them needs a table.
386
391
  */
387
392
  rows(args: {
388
393
  doc: RawDoc;
@@ -457,8 +462,6 @@ export interface AuthHandle {
457
462
  /** The Better-auth database adapter. Opaque to core, which only hands it to Better-auth. */
458
463
  betterAuthAdapter: unknown;
459
464
  }
460
- /** Which blank a feature is being asked to shape — see `FeatureDefinition.blank`. */
461
- export type BlankIntent = 'create' | 'seed';
462
465
  export type WritePlan = {
463
466
  /** What goes on the prototype's own row. */
464
467
  data: Dic;
@@ -487,18 +490,6 @@ export type VersionsTable = {
487
490
  */
488
491
  slug: string;
489
492
  };
490
- /**
491
- * How a feature describes storage it needs, in core's terms.
492
- *
493
- * A `versions` deviates a prototype's own table and a prototype's fields become its columns. Neither
494
- * covers a table that belongs to the **feature** — better-auth's four, an api-key store, an audit
495
- * log. Those were written out as drizzle source inside the schema generator, which is how the
496
- * database layer came to know that a collection called `staff` exists and is special.
497
- *
498
- * No drizzle here, and no SQL: a declaration says what the storage *is*, and the adapter decides
499
- * how to spell it. That is the same line `Adapter` draws, for the same reason — a second adapter
500
- * has to be able to satisfy this.
501
- */
502
493
  /**
503
494
  * What a column holds.
504
495
  *
@@ -530,6 +521,13 @@ export type ColumnDeclaration = {
530
521
  onDelete?: 'cascade' | 'set null';
531
522
  };
532
523
  };
524
+ /**
525
+ * A table that belongs to a feature rather than to a prototype, in core's terms: better-auth's
526
+ * four, the api-key store. A prototype's table comes from its fields; this covers the rest.
527
+ *
528
+ * No drizzle here, and no SQL: a declaration says what the storage *is*, and the adapter decides
529
+ * how to spell it. That is the line `Adapter` draws too, so a second adapter can satisfy it.
530
+ */
533
531
  export type TableDeclaration = {
534
532
  /**
535
533
  * The table's slug, `$`-prefixed to mark it rime-derived — `$authUsers`.
@@ -540,15 +538,3 @@ export type TableDeclaration = {
540
538
  slug: string;
541
539
  columns: ColumnDeclaration[];
542
540
  };
543
- /**
544
- * How a feature describes storage it needs, in core's terms.
545
- *
546
- * A `versions` deviates a prototype's own table and a prototype's fields become its columns. Neither
547
- * covers a table that belongs to the **feature** — better-auth's four, an api-key store, an audit
548
- * log. Those were written out as drizzle source inside the schema generator, which is how the
549
- * database layer came to know that a collection called `staff` exists and is special.
550
- *
551
- * No drizzle here, and no SQL: a declaration says what the storage *is*, and the adapter decides
552
- * how to spell it. That is the same line `Adapter` draws, for the same reason — a second adapter
553
- * has to be able to satisfy this.
554
- */
@@ -1,13 +1 @@
1
1
  export {};
2
- /**
3
- * How a feature describes storage it needs, in core's terms.
4
- *
5
- * A `versions` deviates a prototype's own table and a prototype's fields become its columns. Neither
6
- * covers a table that belongs to the **feature** — better-auth's four, an api-key store, an audit
7
- * log. Those were written out as drizzle source inside the schema generator, which is how the
8
- * database layer came to know that a collection called `staff` exists and is special.
9
- *
10
- * No drizzle here, and no SQL: a declaration says what the storage *is*, and the adapter decides
11
- * how to spell it. That is the same line `Adapter` draws, for the same reason — a second adapter
12
- * has to be able to satisfy this.
13
- */
@@ -61,7 +61,8 @@ export const augmentAuth = (config) => {
61
61
  // Define role field
62
62
  const rolesField = select('roles')
63
63
  .options(...roles)
64
- .defaultValue([defaultRole.value])
64
+ // Never saved empty: an account without a role has the default one.
65
+ .defaultValue([defaultRole.value], { fill: 'save' })
65
66
  .many()
66
67
  .required();
67
68
  if (IS_GENERIC_COLLECTION) {
@@ -6,9 +6,9 @@
6
6
  * purely to carry `validate.password`, which is why it is added here per-operation rather
7
7
  * than declared on the collection in augment.ts.
8
8
  *
9
- * Must run *after* mergeWithBlankDocument. The blank document is built from `config.fields`,
9
+ * Must run *after* mergeWithInitialDocument. The initial document is built from `config.fields`,
10
10
  * and the config map is built from the *data*: augment before the merge and every create
11
- * gains a blank `password`, which then fails its own `.required()` check on the paths that
11
+ * gains an empty `password`, which then fails its own `.required()` check on the paths that
12
12
  * legitimately have no password — better-auth's post-signup callback, which creates the
13
13
  * document with `{ name, email, authUserId }`.
14
14
  *
@@ -17,9 +17,9 @@ const passwordField = text('password')
17
17
  * purely to carry `validate.password`, which is why it is added here per-operation rather
18
18
  * than declared on the collection in augment.ts.
19
19
  *
20
- * Must run *after* mergeWithBlankDocument. The blank document is built from `config.fields`,
20
+ * Must run *after* mergeWithInitialDocument. The initial document is built from `config.fields`,
21
21
  * and the config map is built from the *data*: augment before the merge and every create
22
- * gains a blank `password`, which then fails its own `.required()` check on the paths that
22
+ * gains an empty `password`, which then fails its own `.required()` check on the paths that
23
23
  * legitimately have no password — better-auth's post-signup callback, which creates the
24
24
  * document with `{ name, email, authUserId }`.
25
25
  *
@@ -26,11 +26,8 @@ export declare const authTables: (config: {
26
26
  }[];
27
27
  }) => TableDeclaration[];
28
28
  /**
29
- * What a collection that signs in carries on its own row.
30
- *
31
- * The link to the better-auth user, and — on the collection auth itself derived — the super-admin
32
- * flag. `templateHasAuth` decided the second by testing `slug === 'staff'`; the feature that made
33
- * that collection is the thing that knows which it is.
29
+ * What a collection that signs in carries on its own row: the link to the better-auth user, and,
30
+ * on the staff collection auth derives, the super-admin flag.
34
31
  */
35
32
  export declare const authColumns: (config: {
36
33
  slug: string;
@@ -138,15 +138,11 @@ export const authTables = (config) => {
138
138
  return tables;
139
139
  };
140
140
  /**
141
- * What a collection that signs in carries on its own row.
142
- *
143
- * The link to the better-auth user, and — on the collection auth itself derived — the super-admin
144
- * flag. `templateHasAuth` decided the second by testing `slug === 'staff'`; the feature that made
145
- * that collection is the thing that knows which it is.
141
+ * What a collection that signs in carries on its own row: the link to the better-auth user, and,
142
+ * on the staff collection auth derives, the super-admin flag.
146
143
  */
147
144
  export const authColumns = (config) =>
148
- // Not an auth collection: no link, no flag. `enabled` used to gate this through a
149
- // `FeatureDefinition.columns` seam only auth ever implemented.
145
+ // Not an auth collection: no link, no flag.
150
146
  !config.auth
151
147
  ? []
152
148
  : [
@@ -1,13 +1,8 @@
1
1
  import type { BuiltCollection } from '../config/types.js';
2
2
  /**
3
- * What a collection declaring `auth` has to look like.
3
+ * What a collection declaring `auth` has to look like. `config/validate.server.ts` asks it of every
4
+ * collection.
4
5
  *
5
- * These rules were in `config/validate.server.ts`, which imported `isAuthConfig` to find the
6
- * collections they applied to — core knowing what an auth collection is, to enforce auth's own
7
- * requirements. They are asked through `FeatureDefinition.validate` now, and only of configs where
8
- * `enabled` is true, so nothing here re-tests for `auth`.
9
- *
10
- * The messages are unchanged: they are what a config author sees, and the e2e suite matches on
11
- * some of them.
6
+ * The messages are what a config author sees, and the e2e suite matches on some of them.
12
7
  */
13
8
  export declare const validateAuth: (config: BuiltCollection) => string[];
@@ -1,18 +1,12 @@
1
1
  import { SelectFieldBuilder } from '../../fields/select/index.js';
2
2
  /**
3
- * What a collection declaring `auth` has to look like.
3
+ * What a collection declaring `auth` has to look like. `config/validate.server.ts` asks it of every
4
+ * collection.
4
5
  *
5
- * These rules were in `config/validate.server.ts`, which imported `isAuthConfig` to find the
6
- * collections they applied to — core knowing what an auth collection is, to enforce auth's own
7
- * requirements. They are asked through `FeatureDefinition.validate` now, and only of configs where
8
- * `enabled` is true, so nothing here re-tests for `auth`.
9
- *
10
- * The messages are unchanged: they are what a config author sees, and the e2e suite matches on
11
- * some of them.
6
+ * The messages are what a config author sees, and the e2e suite matches on some of them.
12
7
  */
13
8
  export const validateAuth = (config) => {
14
- // Not an auth collection: nothing here applies. `enabled` used to gate this, through a seam
15
- // only auth ever implemented.
9
+ // Not an auth collection: nothing here applies.
16
10
  if (!config.auth)
17
11
  return [];
18
12
  const errors = [];
@@ -203,10 +203,10 @@ export type BuiltCollection = Omit<Collection<string>, 'icon' | 'versions' | 'up
203
203
  slug: CollectionSlug;
204
204
  type: 'collection';
205
205
  /**
206
- * A document of this config's shape with every default applied, and no id — see
207
- * `prototype/blank.ts`, which every config carries as this method.
206
+ * What a new document starts with: every default applied, and no id — see
207
+ * `prototype/initial.ts`, which every config carries as this method.
208
208
  */
209
- blank(event?: RequestEvent): GenericDoc;
209
+ initial(event?: RequestEvent): GenericDoc;
210
210
  /** Make fields mandatory */
211
211
  fields: FieldBuilder<Field>[];
212
212
  /** The kebab-case version of the slug for urls */
@@ -262,10 +262,10 @@ export type BuiltArea = Omit<Area<string>, 'versions'> & {
262
262
  slug: AreaSlug;
263
263
  type: 'area';
264
264
  /**
265
- * A document of this config's shape with every default applied, and no id — see
266
- * `prototype/blank.ts`, which every config carries as this method.
265
+ * What a new document starts with: every default applied, and no id — see
266
+ * `prototype/initial.ts`, which every config carries as this method.
267
267
  */
268
- blank(event?: RequestEvent): GenericDoc;
268
+ initial(event?: RequestEvent): GenericDoc;
269
269
  /** Make fields mandatory */
270
270
  fields: FieldBuilder<Field>[];
271
271
  /** The kebab-case version of the slug for urls */
@@ -159,6 +159,17 @@ const validateDocumentFields = (documentConfig, config) => {
159
159
  }
160
160
  validateBlockField(block.get.fields, block.name);
161
161
  }
162
+ // A default names block types this list declares. A function default is checked when
163
+ // it runs.
164
+ const initial = field.get.defaultValue;
165
+ if (Array.isArray(initial)) {
166
+ try {
167
+ field.use.completeDefault(initial);
168
+ }
169
+ catch (error) {
170
+ errors.push(`${error.message}, in ${documentConfig.type} ${documentConfig.slug}`);
171
+ }
172
+ }
162
173
  }
163
174
  else if (field instanceof RelationFieldBuilder) {
164
175
  validateRelationField(field);
@@ -1,4 +1,4 @@
1
- import type { DefaultValueFn, FieldValidationFunc, FormField } from '../../../fields/types.js';
1
+ import type { DefaultOptions, DefaultValueFn, FieldValidationFunc, FormField } from '../../../fields/types.js';
2
2
  import { FormFieldBuilder } from './form-field-builder.js';
3
3
  type BooleanField = FormField & {
4
4
  type: any;
@@ -8,7 +8,7 @@ type BooleanField = FormField & {
8
8
  };
9
9
  export declare class BooleanFieldBuilder<T extends BooleanField = BooleanField> extends FormFieldBuilder<T> {
10
10
  constructor(name: string, type: string);
11
- defaultValue(value: boolean | DefaultValueFn<boolean>): this;
11
+ defaultValue(value: boolean | DefaultValueFn<boolean>, options?: DefaultOptions): this;
12
12
  get dataType(): 'boolean';
13
13
  compile(): import("./field-builder.js").WithoutBuilders<T> & {
14
14
  component: import("svelte").Component<any>;
@@ -3,9 +3,12 @@ export class BooleanFieldBuilder extends FormFieldBuilder {
3
3
  constructor(name, type) {
4
4
  super(name, type);
5
5
  this.field.defaultValue = false;
6
+ // `false` is a value: only a missing one is empty.
7
+ this.field.isEmpty = (value) => typeof value !== 'boolean';
6
8
  }
7
- defaultValue(value) {
9
+ defaultValue(value, options) {
8
10
  this.field.defaultValue = value;
11
+ this.field.defaultFill = options?.fill;
9
12
  return this;
10
13
  }
11
14
  get dataType() {
@@ -1,6 +1,6 @@
1
1
  import type { DataType } from './form-field-builder.js';
2
2
  import { FormFieldBuilder } from './form-field-builder.js';
3
- import type { DefaultValueFn, FieldValidationFunc, FormField, Option } from '../../../fields/types.js';
3
+ import type { DefaultOptions, DefaultValueFn, FieldValidationFunc, FormField, Option } from '../../../fields/types.js';
4
4
  type FieldWithOptions = FormField & {
5
5
  options: Option[];
6
6
  defaultValue?: (string | DefaultValueFn<string>) | (string[] | DefaultValueFn<string[]>);
@@ -18,11 +18,11 @@ declare class PickFieldBuilder<T extends FieldWithOptions = FieldWithOptions> ex
18
18
  };
19
19
  }
20
20
  export declare class PickOneFieldBuilder<T extends FieldWithOptions = FieldWithOptions> extends PickFieldBuilder<T> {
21
- defaultValue(value: string | DefaultValueFn<string>): this;
21
+ defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
22
22
  get dataType(): DataType;
23
23
  }
24
24
  export declare class PickManyFieldBuilder<T extends FieldWithOptions = FieldWithOptions> extends PickFieldBuilder<T> {
25
- defaultValue(value: string[] | DefaultValueFn<string[]>): this;
25
+ defaultValue(value: string[] | DefaultValueFn<string[]>, options?: DefaultOptions): this;
26
26
  many(): this;
27
27
  }
28
28
  export {};
@@ -57,8 +57,9 @@ class PickFieldBuilder extends FormFieldBuilder {
57
57
  }
58
58
  }
59
59
  export class PickOneFieldBuilder extends PickFieldBuilder {
60
- defaultValue(value) {
60
+ defaultValue(value, options) {
61
61
  this.field.defaultValue = value;
62
+ this.field.defaultFill = options?.fill;
62
63
  return this;
63
64
  }
64
65
  get dataType() {
@@ -66,8 +67,9 @@ export class PickOneFieldBuilder extends PickFieldBuilder {
66
67
  }
67
68
  }
68
69
  export class PickManyFieldBuilder extends PickFieldBuilder {
69
- defaultValue(value) {
70
+ defaultValue(value, options) {
70
71
  this.field.defaultValue = value;
72
+ this.field.defaultFill = options?.fill;
71
73
  return this;
72
74
  }
73
75
  many() {
@@ -0,0 +1,18 @@
1
+ import type { FieldBuilder } from './builders/field-builder.js';
2
+ import type { Field } from '../../fields/types.js';
3
+ import type { Dic } from '../../util/types.js';
4
+ /** What a field adds to its `use` when its default is a list of items to complete: blocks, tree. */
5
+ export type CompletesDefault<D extends Dic = Dic> = {
6
+ completeDefault(value: D[]): Dic[];
7
+ };
8
+ /**
9
+ * One item of a default list, a block or a tree item, as a document holds it: the initial values
10
+ * of its fields, the values the item names winning, its own lists completed, and a fresh
11
+ * temporary id. A new copy on each call.
12
+ *
13
+ * ```ts
14
+ * completeItem([text('title'), text('intro')], { title: 'Hello' });
15
+ * // { id: 'temp-3f9aK2bQ', title: 'Hello', intro: null }
16
+ * ```
17
+ */
18
+ export declare const completeItem: (fields: FieldBuilder<Field>[], given: Dic) => Dic;
@@ -0,0 +1,32 @@
1
+ import { getValueAtPath, setValueAtPath } from '../../util/object.js';
2
+ import { tempId } from '../../util/random.js';
3
+ import cloneDeep from 'clone-deep';
4
+ import { initialValues } from './initial.js';
5
+ import { isFormField } from './util.js';
6
+ import { walkFields } from './walk.js';
7
+ const completesDefault = (use) => typeof use.completeDefault === 'function';
8
+ /**
9
+ * One item of a default list, a block or a tree item, as a document holds it: the initial values
10
+ * of its fields, the values the item names winning, its own lists completed, and a fresh
11
+ * temporary id. A new copy on each call.
12
+ *
13
+ * ```ts
14
+ * completeItem([text('title'), text('intro')], { title: 'Hello' });
15
+ * // { id: 'temp-3f9aK2bQ', title: 'Hello', intro: null }
16
+ * ```
17
+ */
18
+ export const completeItem = (fields, given) => {
19
+ let item = { ...initialValues(fields), ...cloneDeep(given) };
20
+ // A nested list the item names is completed by its own field; one it leaves out already holds
21
+ // that field's default, from `initialValues`.
22
+ for (const { field, path } of walkFields(fields, { determinate: true })) {
23
+ if (!isFormField(field))
24
+ continue;
25
+ const use = field.use;
26
+ const nested = getValueAtPath(path, given);
27
+ if (completesDefault(use) && Array.isArray(nested)) {
28
+ item = setValueAtPath(path, item, use.completeDefault(nested));
29
+ }
30
+ }
31
+ return { ...item, id: tempId() };
32
+ };