rimecms 1.1.5 → 1.1.6

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.
@@ -3,7 +3,7 @@ import { baseTableName, declaredTableProperty, tableName } from '../naming.serve
3
3
  import { date } from '../../fields/date/index.js';
4
4
  import { generateJunctionTableDefinition } from './relations/junction.server.js';
5
5
  import buildRootTable, {} from './root.server.js';
6
- import { templateDeclaredTable, templateExportRelationsFieldsToTable, templateExportSchema, templateExportTables, templateHead, templateImports, templatePathsTable, templateRelations } from './templates.server.js';
6
+ import { templateDeclaredTable, templateExportSchema, templateExportTables, templateHead, templateImports, templatePathsTable, templateRelations } from './templates.server.js';
7
7
  import write from './write.server.js';
8
8
  export async function generateSchemaString(config) {
9
9
  // Every prototype config in the build, each paired with the features that extend its kind —
@@ -19,7 +19,6 @@ export async function generateSchemaString(config) {
19
19
  let enumTables = [];
20
20
  /** parent table -> its child tables, for the one `defineRelations` at the end. */
21
21
  const relationTree = {};
22
- let relationFieldsExportDic = {};
23
22
  const blocksRegister = [];
24
23
  /** Every resolved reference, joined onto its owner in the same `defineRelations`. */
25
24
  const referenceJoins = [];
@@ -82,10 +81,6 @@ export async function generateSchemaString(config) {
82
81
  for (const [parent, children] of Object.entries(relationsDic)) {
83
82
  (relationTree[parent] ??= []).push(...children);
84
83
  }
85
- relationFieldsExportDic = {
86
- ...relationFieldsExportDic,
87
- [rootTableName]: relationFieldsMap
88
- };
89
84
  schema.push(prototypeSchema, junctionTable);
90
85
  // A collection with `$url` keeps its pages' addresses in a table of their own, off the base
91
86
  // table: an address belongs to the page, not to one of its versions.
@@ -105,7 +100,6 @@ export async function generateSchemaString(config) {
105
100
  schema.push(templateExportTables(enumTables));
106
101
  // After `tables`, which `defineRelations` takes as its first argument.
107
102
  schema.push(templateRelations(relationTree, referenceJoins));
108
- schema.push(templateExportRelationsFieldsToTable(relationFieldsExportDic));
109
103
  schema.push(templateExportSchema({ enumTables }));
110
104
  return schema.join('\n').replace(/\n{3,}/g, '\n\n');
111
105
  }
@@ -1,8 +1,8 @@
1
- import type { LocaleConfig } from '../../core/locale/types.js';
1
+ import type { ColumnDeclaration } from '../../core/adapter.js';
2
2
  import type { FieldBuilder } from '../../core/fields/builders/field-builder.js';
3
+ import type { LocaleConfig } from '../../core/locale/types.js';
3
4
  import type { Field } from '../../fields/types.js';
4
5
  import type { TableName } from '../naming.server.js';
5
- import type { ColumnDeclaration } from '../../core/adapter.js';
6
6
  /** A relation field on a prototype: which collection it points at, and whether it is localized. */
7
7
  export type RelationFieldsMap = Record<string, {
8
8
  to: string;
@@ -1,6 +1,6 @@
1
1
  import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
2
2
  import { walkFields } from '../../core/fields/walk.js';
3
- import { RelationFieldBuilder } from '../../fields/relation/index.js';
3
+ import { isRelationField } from '../../fields/relation/index.js';
4
4
  import { tableName as buildTableName, getSchemaColumnNames } from '../naming.server.js';
5
5
  import { toSchemaColumn } from './column.server.js';
6
6
  import { templateDeclaredColumn, templateLocale, templateParent, templateTable } from './templates.server.js';
@@ -63,7 +63,7 @@ const buildRootTable = async ({ fields: incomingFields, tableName, rootName, has
63
63
  };
64
64
  for (const field of fields) {
65
65
  // Junction rows: no column here, and the relations table wants to know it exists.
66
- if (field instanceof RelationFieldBuilder) {
66
+ if (isRelationField(field)) {
67
67
  if (field.get.localized) {
68
68
  relationFieldsHasLocale = true;
69
69
  }
@@ -179,18 +179,6 @@ export declare const templateFieldRelationColumn: (slug: string) => string;
179
179
  * ```
180
180
  */
181
181
  export declare const templateRelationFieldsTable: ({ table, junctionTable, relations, hasLocale }: FieldsRelationTableArgs) => string;
182
- /**
183
- * Generates an export of relation field mappings for runtime use
184
- * Creates a record mapping table names to their relation configurations
185
- *
186
- * @example
187
- * ```typescript
188
- * export const relationFieldsMap: Record<string, any> = {
189
- * pages: {"medias":{"to":"medias"},"categories":{"to":"categories"}}
190
- * }
191
- * ```
192
- */
193
- export declare const templateExportRelationsFieldsToTable: (relationFieldsDic: Record<string, string>) => string;
194
182
  /**
195
183
  * Generates an export of all tables for runtime use
196
184
  * Creates a record with all table definitions and proper TypeScript types
@@ -301,30 +301,6 @@ export const ${junctionTable} = sqliteTable('${junctionTable}', {
301
301
  ${hasLocale ? `locale: text('locale'),` : ''}
302
302
  }${templateIndexes(junctionTable, ['ownerId', ...relations.map((rel) => `${rel}Id`)])})
303
303
  `;
304
- /**
305
- * Generates an export of relation field mappings for runtime use
306
- * Creates a record mapping table names to their relation configurations
307
- *
308
- * @example
309
- * ```typescript
310
- * export const relationFieldsMap: Record<string, any> = {
311
- * pages: {"medias":{"to":"medias"},"categories":{"to":"categories"}}
312
- * }
313
- * ```
314
- */
315
- export const templateExportRelationsFieldsToTable = (relationFieldsDic) => {
316
- const content = [];
317
- for (const [table, dic] of Object.entries(relationFieldsDic)) {
318
- content.push(dedent `
319
- ${table} : ${JSON.stringify(dic)}
320
- `);
321
- }
322
- return dedent `
323
- export const relationFieldsMap: Record<string, any> = {
324
- ${content.join(',\n ')}
325
- }
326
- `;
327
- };
328
304
  /**
329
305
  * Generates an export of all tables for runtime use
330
306
  * Creates a record with all table definitions and proper TypeScript types
@@ -4,7 +4,6 @@ import type { ConfigContext } from '../core/rime.server.js';
4
4
  import type { GetRegisterType } from '../index.js';
5
5
  import { type SqliteDriver } from './connect.server.js';
6
6
  import generateSchema from './generate-schema/index.server.js';
7
- import type { RelationFieldsMap } from './generate-schema/root.server.js';
8
7
  import type { GenericTable, SqliteDatabase } from './types.server.js';
9
8
  type Schema = GetRegisterType<'Schema'>;
10
9
  export type { SqliteDriver };
@@ -37,5 +36,4 @@ export type SqliteAdapter = Adapter & {
37
36
  getTable<T>(key: string): T extends any ? GenericTable : T;
38
37
  tableForSlug<T>(slug: string): T extends any ? GenericTable : T;
39
38
  readonly schema: Schema;
40
- readonly relationFieldsMap: RelationFieldsMap;
41
39
  };
@@ -69,9 +69,6 @@ const createAdapter = async (args) => {
69
69
  },
70
70
  get schema() {
71
71
  return schema.default;
72
- },
73
- get relationFieldsMap() {
74
- return schema.relationFieldsMap;
75
72
  }
76
73
  };
77
74
  };
@@ -1,6 +1,6 @@
1
1
  import { getFieldAtPath, resolvedReferencesOf } from '../core/fields/util.js';
2
2
  import { getColumns } from 'drizzle-orm';
3
- import { RelationFieldBuilder } from '../fields/relation/index.js';
3
+ import { isRelationField } from '../fields/relation/index.js';
4
4
  import { baseTableName, childTableNames, joinName, tableName } from './naming.server.js';
5
5
  /** What a joined target is projected to, beside its `id`: whatever of these its table has. */
6
6
  const JOINED_COLUMNS = ['name', 'email', 'title', 'filename'];
@@ -95,7 +95,7 @@ export const buildWithParam = (args) => {
95
95
  const fieldConfig = getFieldAtPath(path, documentConfig.fields);
96
96
  // Each branch is where the field's rows are stored: the junction table, a child table, or a
97
97
  // column of the row itself.
98
- if (fieldConfig instanceof RelationFieldBuilder) {
98
+ if (isRelationField(fieldConfig)) {
99
99
  directRelationPaths.push(path);
100
100
  }
101
101
  else if (fieldConfig && storageKinds(fieldConfig).length) {
@@ -1,7 +1,7 @@
1
1
  import { RimeError } from '../core/errors/index.js';
2
2
  import { getFieldAtPath } from '../core/fields/util.js';
3
3
  import { logger } from '../core/logger.server.js';
4
- import { RelationFieldBuilder } from '../fields/relation/index.js';
4
+ import { isRelationField } from '../fields/relation/index.js';
5
5
  import {} from '../index.js';
6
6
  import * as drizzleORM from 'drizzle-orm';
7
7
  import { and, eq, getTableColumns, inArray, or } from 'drizzle-orm';
@@ -119,7 +119,7 @@ export const buildWhereParam = ({ query, slug, db, locale, tables, configCtx, ba
119
119
  }
120
120
  }
121
121
  // If still not found or not a relation field, log warning and return false condition
122
- if (!(fieldConfig instanceof RelationFieldBuilder)) {
122
+ if (!isRelationField(fieldConfig)) {
123
123
  const message = `the query contains the field "${column}", not found for ${documentConfig.slug} document`;
124
124
  logger.warn(message);
125
125
  // Return a condition that will always be false instead of returning false
@@ -3,7 +3,7 @@ import { getRequestEvent } from '$app/server';
3
3
  import { isFormField } from '../../fields/util.js';
4
4
  import { walkFields } from '../../fields/walk.js';
5
5
  import { logger } from '../../logger.server.js';
6
- import { RelationFieldBuilder } from '../../../fields/relation/index.js';
6
+ import { isRelationField } from '../../../fields/relation/index.js';
7
7
  import { getValueAtPath, setValueAtPath } from '../../../util/object.js';
8
8
  import { buildConfigMap } from '../config-map/index.js';
9
9
  /**
@@ -93,7 +93,7 @@ const defaultRelationValue = async (config, key, adapter) => {
93
93
  };
94
94
  /** A relation's default becomes junction rows, checked against the collection. */
95
95
  export const getDefaultValue = async ({ key, config, adapter }) => {
96
- if (config instanceof RelationFieldBuilder) {
96
+ if (isRelationField(config)) {
97
97
  return await defaultRelationValue(config, key, adapter);
98
98
  }
99
99
  return config.use.defaultValue({ event: getRequestEvent() });
@@ -1,4 +1,4 @@
1
- import { RelationFieldBuilder } from '../../../../fields/relation/index.js';
1
+ import { isRelationField } from '../../../../fields/relation/index.js';
2
2
  import { Relation } from '../../../../fields/relation/relation.js';
3
3
  import { getValueAtPath, isObjectLiteral } from '../../../../util/object.js';
4
4
  export const extractRelations = ({ ownerId, data, configMap, locale }) => {
@@ -6,7 +6,7 @@ export const extractRelations = ({ ownerId, data, configMap, locale }) => {
6
6
  // The config map keys every field the document holds; relations are the ones stored as junction
7
7
  // rows, and the key is the `path` those rows carry.
8
8
  for (const [path, config] of Object.entries(configMap)) {
9
- if (config instanceof RelationFieldBuilder) {
9
+ if (isRelationField(config)) {
10
10
  const value = getValueAtPath(path, data);
11
11
  // One value outside an array is a list of one.
12
12
  const entries = Array.isArray(value) ? value : value ? [value] : [];
@@ -1,9 +1,9 @@
1
1
  import { walkFields } from '../../../fields/walk.js';
2
- import { RelationFieldBuilder } from '../../../../fields/relation/index.js';
2
+ import { isRelationField } from '../../../../fields/relation/index.js';
3
3
  /** The first relation marked `isThumbnail()`, at a path a config alone can name. */
4
4
  export function findThumbnailField(fields = [], basePath = '') {
5
5
  for (const { field, path } of walkFields(fields, { path: basePath, determinate: true })) {
6
- if (field instanceof RelationFieldBuilder && field.get.isThumbnail === true) {
6
+ if (isRelationField(field) && field.get.isThumbnail === true) {
7
7
  return { field, path };
8
8
  }
9
9
  }
@@ -7,7 +7,7 @@ import { fileForDocument } from '../../../collection/upload/util/converter.serve
7
7
  import { VERSIONS_STATUS } from '../constant.js';
8
8
  import { withVersionsSuffix } from '../naming.js';
9
9
  import { VersionOperations } from '../strategy.js';
10
- import { RelationFieldBuilder } from '../../../../../fields/relation/index.js';
10
+ import { isRelationField } from '../../../../../fields/relation/index.js';
11
11
  import { Relation } from '../../../../../fields/relation/relation.js';
12
12
  import { getValueAtPath, isObjectLiteral, omit, recursiveRemoveKeys, setValueAtPath } from '../../../../../util/object.js';
13
13
  import { retireAutoSaves } from '../retire-auto-saves.server.js';
@@ -191,7 +191,7 @@ async function prepareDataForNewVersion(args) {
191
191
  // A relation sent back as documents, read at depth 1, keeps what it points to: the strip
192
192
  // below takes every `id`, a document's own included.
193
193
  for (const [path, field] of Object.entries(buildConfigMap(data, config.fields))) {
194
- if (!(field instanceof RelationFieldBuilder))
194
+ if (!isRelationField(field))
195
195
  continue;
196
196
  const value = getValueAtPath(path, data);
197
197
  if (!Array.isArray(value))
@@ -39,6 +39,14 @@ export declare class RelationFieldBuilder<Doc extends GenericDoc = GenericDoc> e
39
39
  protected generateType(): string;
40
40
  }
41
41
  export declare const relation: (name: string) => RelationFieldBuilder<GenericDoc>;
42
+ /**
43
+ * A relation, told by its type. `instanceof` is not enough: a dev reload can load this class
44
+ * twice, and a relation built from the other copy then fails it. The schema generator once took
45
+ * such a relation for a text column, and dropped the junction table with every row in it.
46
+ */
47
+ export declare const isRelationField: (field: {
48
+ type?: string;
49
+ } | null | undefined) => field is RelationFieldBuilder;
42
50
  /****************************************************/
43
51
  export type RelationField<Doc extends GenericDoc = GenericDoc> = FormField & {
44
52
  type: 'relation';
@@ -76,3 +76,9 @@ export class RelationFieldBuilder extends FormFieldBuilder {
76
76
  }
77
77
  }
78
78
  export const relation = (name) => new RelationFieldBuilder(name);
79
+ /**
80
+ * A relation, told by its type. `instanceof` is not enough: a dev reload can load this class
81
+ * twice, and a relation built from the other copy then fails it. The schema generator once took
82
+ * such a relation for a text column, and dropped the junction table with every row in it.
83
+ */
84
+ export const isRelationField = (field) => field?.type === 'relation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "packageManager": "bun@1.3.0",
6
6
  "scripts": {