@loomcore/common 0.0.37 → 0.0.39

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.
@@ -4,6 +4,6 @@ export interface IEntity {
4
4
  _orgId?: AppId;
5
5
  }
6
6
  export declare const EntitySchema: import("@sinclair/typebox").TObject<{
7
- _id: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNumber]>;
7
+ _id: import("@sinclair/typebox").TSchema;
8
8
  _orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnsafe<unknown>>;
9
9
  }>;
@@ -1,6 +1,7 @@
1
1
  import { Type } from '@sinclair/typebox';
2
- import { IdSchema } from '../validation/id-schema.provider.js';
2
+ import { getIdSchema } from '../validation/typebox-extensions.js';
3
+ const idSchema = getIdSchema();
3
4
  export const EntitySchema = Type.Object({
4
- _id: IdSchema,
5
- _orgId: Type.Optional(Type.Unsafe({ ...IdSchema, title: 'Organization ID' }))
5
+ _id: idSchema,
6
+ _orgId: Type.Optional(Type.Unsafe({ ...idSchema, title: 'Organization ID' }))
6
7
  });
@@ -1 +1,2 @@
1
1
  export * from './sort-direction.type.js';
2
+ export * from './app.types.js';
@@ -1 +1,2 @@
1
1
  export * from './sort-direction.type.js';
2
+ export * from './app.types.js';
@@ -1,4 +1,6 @@
1
1
  import { Kind, TSchema, NumberOptions } from '@sinclair/typebox';
2
+ export declare const setIdSchema: (schema: TSchema) => void;
3
+ export declare const getIdSchema: () => TSchema;
2
4
  export declare function TypeboxIsoDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
3
5
  export declare function TypeboxDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
4
6
  export declare function TypeboxObjectId(options?: object): import("@sinclair/typebox").TString;
@@ -2,6 +2,22 @@ import { Type, Kind, ValueGuard } from '@sinclair/typebox';
2
2
  import { TypeRegistry } from '@sinclair/typebox';
3
3
  import { Decimal as _Decimal } from 'decimal.js';
4
4
  import { Value } from '@sinclair/typebox/value';
5
+ let idSchemaInstance;
6
+ export const setIdSchema = (schema) => {
7
+ if (idSchemaInstance) {
8
+ throw new Error('IdSchema has already been initialized and cannot be set again.');
9
+ }
10
+ if (!schema) {
11
+ throw new Error('Schema cannot be null or undefined.');
12
+ }
13
+ idSchemaInstance = schema;
14
+ };
15
+ export const getIdSchema = () => {
16
+ if (!idSchemaInstance) {
17
+ throw new Error('IdSchema has not been initialized. Please call setIdSchema() at application startup.');
18
+ }
19
+ return idSchemaInstance;
20
+ };
5
21
  export function TypeboxIsoDate(options = {}) {
6
22
  const dateTransform = Type.Transform(Type.String({ format: 'date-time', ...options }))
7
23
  .Decode(value => new Date(value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/common",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "private": false,
5
5
  "description": "Loom Core Models- common models, interfaces, types, and utils for Loom Core. All things common to both api and client apps.",
6
6
  "scripts": {
@@ -1,2 +0,0 @@
1
- export declare let IdSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNumber]>;
2
- export declare function setIdSchema(schema: typeof IdSchema): void;
@@ -1,8 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- export let IdSchema = Type.Union([
3
- Type.String({ title: 'ID' }),
4
- Type.Number({ title: 'ID', integer: true, minimum: 1 })
5
- ]);
6
- export function setIdSchema(schema) {
7
- IdSchema = schema;
8
- }