@revisium/schema-toolkit 0.2.0

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/dist/consts/index.cjs +26 -0
  4. package/dist/consts/index.cjs.map +1 -0
  5. package/dist/consts/index.d.cts +17 -0
  6. package/dist/consts/index.d.ts +17 -0
  7. package/dist/consts/index.js +23 -0
  8. package/dist/consts/index.js.map +1 -0
  9. package/dist/index.cjs +1874 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +13 -0
  12. package/dist/index.d.ts +13 -0
  13. package/dist/index.js +1787 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/json-patch.types-DiJBqfxV.d.ts +28 -0
  16. package/dist/json-patch.types-lByaF-OL.d.cts +28 -0
  17. package/dist/json-string.store-O1J0j-a1.d.cts +228 -0
  18. package/dist/json-string.store-S9FXT39Q.d.ts +228 -0
  19. package/dist/json.types-46Cq-WxU.d.cts +8 -0
  20. package/dist/json.types-46Cq-WxU.d.ts +8 -0
  21. package/dist/lib/index.cjs +1346 -0
  22. package/dist/lib/index.cjs.map +1 -0
  23. package/dist/lib/index.d.cts +91 -0
  24. package/dist/lib/index.d.ts +91 -0
  25. package/dist/lib/index.js +1315 -0
  26. package/dist/lib/index.js.map +1 -0
  27. package/dist/mocks/index.cjs +92 -0
  28. package/dist/mocks/index.cjs.map +1 -0
  29. package/dist/mocks/index.d.cts +26 -0
  30. package/dist/mocks/index.d.ts +26 -0
  31. package/dist/mocks/index.js +81 -0
  32. package/dist/mocks/index.js.map +1 -0
  33. package/dist/model/index.cjs +718 -0
  34. package/dist/model/index.cjs.map +1 -0
  35. package/dist/model/index.d.cts +19 -0
  36. package/dist/model/index.d.ts +19 -0
  37. package/dist/model/index.js +697 -0
  38. package/dist/model/index.js.map +1 -0
  39. package/dist/plugins/index.cjs +122 -0
  40. package/dist/plugins/index.cjs.map +1 -0
  41. package/dist/plugins/index.d.cts +21 -0
  42. package/dist/plugins/index.d.ts +21 -0
  43. package/dist/plugins/index.js +112 -0
  44. package/dist/plugins/index.js.map +1 -0
  45. package/dist/schema.types-Q3MYTp8z.d.cts +68 -0
  46. package/dist/schema.types-Q3MYTp8z.d.ts +68 -0
  47. package/dist/types/index.cjs +15 -0
  48. package/dist/types/index.cjs.map +1 -0
  49. package/dist/types/index.d.cts +56 -0
  50. package/dist/types/index.d.ts +56 -0
  51. package/dist/types/index.js +13 -0
  52. package/dist/types/index.js.map +1 -0
  53. package/dist/validation-schemas/index.cjs +380 -0
  54. package/dist/validation-schemas/index.cjs.map +1 -0
  55. package/dist/validation-schemas/index.d.cts +32 -0
  56. package/dist/validation-schemas/index.d.ts +32 -0
  57. package/dist/validation-schemas/index.js +365 -0
  58. package/dist/validation-schemas/index.js.map +1 -0
  59. package/package.json +169 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Anton Kashirov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ <div align="center">
2
+
3
+ # @revisium/schema-toolkit
4
+
5
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=revisium_schema-toolkit&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=revisium_schema-toolkit)
6
+ [![codecov](https://codecov.io/gh/revisium/schema-toolkit/graph/badge.svg?token=OLFXI79CN3)](https://codecov.io/gh/revisium/schema-toolkit)
7
+ [![GitHub License](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/revisium/prisma-pg-json/blob/master/LICENSE)
8
+ [![GitHub Release](https://img.shields.io/github/v/release/revisium/schema-toolkit)](https://github.com/revisium/schema-toolkit/releases)
9
+
10
+ **Universal TypeScript toolkit for JSON Schema definitions used across the Revisium ecosystem.**
11
+
12
+ </div>
13
+
14
+ ## Overview
15
+
16
+ `@revisium/schema-toolkit` provides framework-agnostic TypeScript types, system schemas, runtime stores, utilities, and testing helpers for working with JSON Schema in Revisium projects. This package contains shared code used by `revisium-core`, `revisium-endpoint`, and `revisium-admin`.
17
+
18
+ ## Features
19
+
20
+ - 🎯 **TypeScript Types** - Complete type definitions for JSON Schema, JSON Patch, JSON Value Patch, and migrations
21
+ - 🔧 **System Schemas** - Pre-defined schemas for Revisium system fields (row ID, timestamps, file handling, etc.)
22
+ - 🏪 **Runtime Stores** - Schema and value store classes for runtime manipulation
23
+ - 🛠️ **Utilities** - 18+ utility functions for schema operations, patches, foreign keys, and more
24
+ - 🧪 **Test Utilities** - Helper functions for generating mock schemas in tests
25
+ - ✅ **Validation Schemas** - Ajv-compatible validation schemas (optional)
26
+ - 🌐 **Framework Agnostic** - No dependencies on backend/frontend frameworks (only `nanoid` for ID generation)
27
+ - 📦 **Tree-shakeable** - Use only what you need with ES modules
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @revisium/schema-toolkit
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### TypeScript Types
38
+
39
+ ```typescript
40
+ import {
41
+ JsonSchema,
42
+ JsonObjectSchema,
43
+ JsonSchemaTypeName,
44
+ } from '@revisium/schema-toolkit/types';
45
+
46
+ const userSchema: JsonObjectSchema = {
47
+ type: JsonSchemaTypeName.Object,
48
+ properties: {
49
+ name: { type: JsonSchemaTypeName.String, default: '' },
50
+ age: { type: JsonSchemaTypeName.Number, default: 0 },
51
+ },
52
+ };
53
+ ```
54
+
55
+ ### System Schemas
56
+
57
+ ```typescript
58
+ import {
59
+ rowIdSchema,
60
+ rowCreatedAtSchema,
61
+ fileSchema,
62
+ } from '@revisium/schema-toolkit/plugins';
63
+ ```
64
+
65
+ ### Model Stores
66
+
67
+ ```typescript
68
+ import {
69
+ createJsonSchemaStore,
70
+ createJsonValueStore,
71
+ } from '@revisium/schema-toolkit/lib';
72
+
73
+ // Create schema store
74
+ const schemaStore = createJsonSchemaStore({
75
+ type: 'object',
76
+ properties: {
77
+ name: { type: 'string', default: '' },
78
+ },
79
+ });
80
+
81
+ // Create value store
82
+ const valueStore = createJsonValueStore(
83
+ schemaStore,
84
+ 'row-id-123',
85
+ { name: 'John' }
86
+ );
87
+ ```
88
+
89
+ ### Utilities
90
+
91
+ ```typescript
92
+ import {
93
+ applyPatches,
94
+ getForeignKeysFromSchema,
95
+ resolveRefs,
96
+ } from '@revisium/schema-toolkit/lib';
97
+
98
+ // Apply JSON patches to schema
99
+ const updatedSchema = applyPatches(schema, patches);
100
+
101
+ // Get foreign keys from schema
102
+ const foreignKeys = getForeignKeysFromSchema(schemaStore);
103
+
104
+ // Resolve $ref in schemas (endpoint feature)
105
+ const resolved = resolveRefs(schemaWithRefs);
106
+ ```
107
+
108
+ ### Test Utilities
109
+
110
+ ```typescript
111
+ import {
112
+ getStringSchema,
113
+ getObjectSchema,
114
+ getRefSchema,
115
+ } from '@revisium/schema-toolkit/mocks';
116
+
117
+ const mockSchema = getObjectSchema({
118
+ name: getStringSchema(),
119
+ userId: getStringSchema({ foreignKey: 'User' }),
120
+ avatar: getRefSchema('File'),
121
+ });
122
+ ```
123
+
124
+ ## API Reference
125
+
126
+ ### Entry Points
127
+
128
+ - `@revisium/schema-toolkit` - All exports (convenience)
129
+ - `@revisium/schema-toolkit/types` - TypeScript types only
130
+ - `@revisium/schema-toolkit/plugins` - System schemas
131
+ - `@revisium/schema-toolkit/mocks` - Test utilities
132
+ - `@revisium/schema-toolkit/consts` - Constants (CustomSchemeKeywords, SystemSchemaIds)
133
+ - `@revisium/schema-toolkit/model` - Schema and value stores
134
+ - `@revisium/schema-toolkit/lib` - Utility functions
135
+ - `@revisium/schema-toolkit/validation-schemas` - Ajv validation schemas
136
+
137
+ ### Key Utilities
138
+
139
+ **Schema Operations:**
140
+ - `createJsonSchemaStore(schema)` - Create runtime schema store
141
+ - `getJsonSchemaStoreByPath(store, path)` - Navigate schema by JSON pointer
142
+ - `applyPatches(schema, patches)` - Apply JSON Patch operations
143
+
144
+ **Value Operations:**
145
+ - `createJsonValueStore(schema, rowId, data)` - Create runtime value store
146
+ - `getJsonValueStoreByPath(store, path)` - Navigate value by JSON pointer
147
+
148
+ **Foreign Keys:**
149
+ - `getForeignKeysFromSchema(store)` - Extract foreign keys from schema
150
+ - `getForeignKeysFromValue(store)` - Extract foreign key values from data
151
+ - `replaceForeignKeyValue(store, fromId, toId)` - Replace foreign key references
152
+
153
+ **Other:**
154
+ - `resolveRefs(schema)` - Resolve $ref to inline schemas
155
+ - `validateJsonFieldName(name)` - Validate field name format
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ # Install dependencies
161
+ npm install
162
+
163
+ # Build
164
+ npm run build
165
+
166
+ # Run tests
167
+ npm test
168
+
169
+ # Run tests with coverage
170
+ npm run test:cov
171
+
172
+ # Lint
173
+ npm run lint:ci
174
+
175
+ # Format
176
+ npm run format
177
+
178
+ # Type check
179
+ npm run tsc
180
+ ```
181
+
182
+ ## License
183
+
184
+ MIT
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // src/consts/system-schema-ids.ts
4
+ var SystemSchemaIds = /* @__PURE__ */ ((SystemSchemaIds2) => {
5
+ SystemSchemaIds2["RowId"] = "urn:jsonschema:io:revisium:row-id-schema:1.0.0";
6
+ SystemSchemaIds2["RowCreatedId"] = "urn:jsonschema:io:revisium:row-created-id-schema:1.0.0";
7
+ SystemSchemaIds2["RowVersionId"] = "urn:jsonschema:io:revisium:row-version-id-schema:1.0.0";
8
+ SystemSchemaIds2["RowCreatedAt"] = "urn:jsonschema:io:revisium:row-created-at-schema:1.0.0";
9
+ SystemSchemaIds2["RowPublishedAt"] = "urn:jsonschema:io:revisium:row-published-at-schema:1.0.0";
10
+ SystemSchemaIds2["RowUpdatedAt"] = "urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0";
11
+ SystemSchemaIds2["RowHash"] = "urn:jsonschema:io:revisium:row-hash-schema:1.0.0";
12
+ SystemSchemaIds2["RowSchemaHash"] = "urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0";
13
+ SystemSchemaIds2["File"] = "urn:jsonschema:io:revisium:file-schema:1.0.0";
14
+ return SystemSchemaIds2;
15
+ })(SystemSchemaIds || {});
16
+
17
+ // src/consts/index.ts
18
+ var CustomSchemeKeywords = /* @__PURE__ */ ((CustomSchemeKeywords2) => {
19
+ CustomSchemeKeywords2["ForeignKey"] = "foreignKey";
20
+ return CustomSchemeKeywords2;
21
+ })(CustomSchemeKeywords || {});
22
+
23
+ exports.CustomSchemeKeywords = CustomSchemeKeywords;
24
+ exports.SystemSchemaIds = SystemSchemaIds;
25
+ //# sourceMappingURL=index.cjs.map
26
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/consts/system-schema-ids.ts","../../src/consts/index.ts"],"names":["SystemSchemaIds","CustomSchemeKeywords"],"mappings":";;;AAAO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AACL,EAAAA,iBAAA,OAAA,CAAA,GAAQ,gDAAA;AACR,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,gBAAA,CAAA,GAAiB,0DAAA;AACjB,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,SAAA,CAAA,GAAU,kDAAA;AACV,EAAAA,iBAAA,eAAA,CAAA,GAAgB,yDAAA;AAChB,EAAAA,iBAAA,MAAA,CAAA,GAAO,8CAAA;AATG,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;;ACAL,IAAK,oBAAA,qBAAAC,qBAAAA,KAAL;AACL,EAAAA,sBAAA,YAAA,CAAA,GAAa,YAAA;AADH,EAAA,OAAAA,qBAAAA;AAAA,CAAA,EAAA,oBAAA,IAAA,EAAA","file":"index.cjs","sourcesContent":["export enum SystemSchemaIds {\n RowId = 'urn:jsonschema:io:revisium:row-id-schema:1.0.0',\n RowCreatedId = 'urn:jsonschema:io:revisium:row-created-id-schema:1.0.0',\n RowVersionId = 'urn:jsonschema:io:revisium:row-version-id-schema:1.0.0',\n RowCreatedAt = 'urn:jsonschema:io:revisium:row-created-at-schema:1.0.0',\n RowPublishedAt = 'urn:jsonschema:io:revisium:row-published-at-schema:1.0.0',\n RowUpdatedAt = 'urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0',\n RowHash = 'urn:jsonschema:io:revisium:row-hash-schema:1.0.0',\n RowSchemaHash = 'urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0',\n File = 'urn:jsonschema:io:revisium:file-schema:1.0.0',\n}\n","export enum CustomSchemeKeywords {\n ForeignKey = 'foreignKey',\n}\n\nexport * from './system-schema-ids.js';\n"]}
@@ -0,0 +1,17 @@
1
+ declare enum SystemSchemaIds {
2
+ RowId = "urn:jsonschema:io:revisium:row-id-schema:1.0.0",
3
+ RowCreatedId = "urn:jsonschema:io:revisium:row-created-id-schema:1.0.0",
4
+ RowVersionId = "urn:jsonschema:io:revisium:row-version-id-schema:1.0.0",
5
+ RowCreatedAt = "urn:jsonschema:io:revisium:row-created-at-schema:1.0.0",
6
+ RowPublishedAt = "urn:jsonschema:io:revisium:row-published-at-schema:1.0.0",
7
+ RowUpdatedAt = "urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0",
8
+ RowHash = "urn:jsonschema:io:revisium:row-hash-schema:1.0.0",
9
+ RowSchemaHash = "urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0",
10
+ File = "urn:jsonschema:io:revisium:file-schema:1.0.0"
11
+ }
12
+
13
+ declare enum CustomSchemeKeywords {
14
+ ForeignKey = "foreignKey"
15
+ }
16
+
17
+ export { CustomSchemeKeywords, SystemSchemaIds };
@@ -0,0 +1,17 @@
1
+ declare enum SystemSchemaIds {
2
+ RowId = "urn:jsonschema:io:revisium:row-id-schema:1.0.0",
3
+ RowCreatedId = "urn:jsonschema:io:revisium:row-created-id-schema:1.0.0",
4
+ RowVersionId = "urn:jsonschema:io:revisium:row-version-id-schema:1.0.0",
5
+ RowCreatedAt = "urn:jsonschema:io:revisium:row-created-at-schema:1.0.0",
6
+ RowPublishedAt = "urn:jsonschema:io:revisium:row-published-at-schema:1.0.0",
7
+ RowUpdatedAt = "urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0",
8
+ RowHash = "urn:jsonschema:io:revisium:row-hash-schema:1.0.0",
9
+ RowSchemaHash = "urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0",
10
+ File = "urn:jsonschema:io:revisium:file-schema:1.0.0"
11
+ }
12
+
13
+ declare enum CustomSchemeKeywords {
14
+ ForeignKey = "foreignKey"
15
+ }
16
+
17
+ export { CustomSchemeKeywords, SystemSchemaIds };
@@ -0,0 +1,23 @@
1
+ // src/consts/system-schema-ids.ts
2
+ var SystemSchemaIds = /* @__PURE__ */ ((SystemSchemaIds2) => {
3
+ SystemSchemaIds2["RowId"] = "urn:jsonschema:io:revisium:row-id-schema:1.0.0";
4
+ SystemSchemaIds2["RowCreatedId"] = "urn:jsonschema:io:revisium:row-created-id-schema:1.0.0";
5
+ SystemSchemaIds2["RowVersionId"] = "urn:jsonschema:io:revisium:row-version-id-schema:1.0.0";
6
+ SystemSchemaIds2["RowCreatedAt"] = "urn:jsonschema:io:revisium:row-created-at-schema:1.0.0";
7
+ SystemSchemaIds2["RowPublishedAt"] = "urn:jsonschema:io:revisium:row-published-at-schema:1.0.0";
8
+ SystemSchemaIds2["RowUpdatedAt"] = "urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0";
9
+ SystemSchemaIds2["RowHash"] = "urn:jsonschema:io:revisium:row-hash-schema:1.0.0";
10
+ SystemSchemaIds2["RowSchemaHash"] = "urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0";
11
+ SystemSchemaIds2["File"] = "urn:jsonschema:io:revisium:file-schema:1.0.0";
12
+ return SystemSchemaIds2;
13
+ })(SystemSchemaIds || {});
14
+
15
+ // src/consts/index.ts
16
+ var CustomSchemeKeywords = /* @__PURE__ */ ((CustomSchemeKeywords2) => {
17
+ CustomSchemeKeywords2["ForeignKey"] = "foreignKey";
18
+ return CustomSchemeKeywords2;
19
+ })(CustomSchemeKeywords || {});
20
+
21
+ export { CustomSchemeKeywords, SystemSchemaIds };
22
+ //# sourceMappingURL=index.js.map
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/consts/system-schema-ids.ts","../../src/consts/index.ts"],"names":["SystemSchemaIds","CustomSchemeKeywords"],"mappings":";AAAO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AACL,EAAAA,iBAAA,OAAA,CAAA,GAAQ,gDAAA;AACR,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,gBAAA,CAAA,GAAiB,0DAAA;AACjB,EAAAA,iBAAA,cAAA,CAAA,GAAe,wDAAA;AACf,EAAAA,iBAAA,SAAA,CAAA,GAAU,kDAAA;AACV,EAAAA,iBAAA,eAAA,CAAA,GAAgB,yDAAA;AAChB,EAAAA,iBAAA,MAAA,CAAA,GAAO,8CAAA;AATG,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;;ACAL,IAAK,oBAAA,qBAAAC,qBAAAA,KAAL;AACL,EAAAA,sBAAA,YAAA,CAAA,GAAa,YAAA;AADH,EAAA,OAAAA,qBAAAA;AAAA,CAAA,EAAA,oBAAA,IAAA,EAAA","file":"index.js","sourcesContent":["export enum SystemSchemaIds {\n RowId = 'urn:jsonschema:io:revisium:row-id-schema:1.0.0',\n RowCreatedId = 'urn:jsonschema:io:revisium:row-created-id-schema:1.0.0',\n RowVersionId = 'urn:jsonschema:io:revisium:row-version-id-schema:1.0.0',\n RowCreatedAt = 'urn:jsonschema:io:revisium:row-created-at-schema:1.0.0',\n RowPublishedAt = 'urn:jsonschema:io:revisium:row-published-at-schema:1.0.0',\n RowUpdatedAt = 'urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0',\n RowHash = 'urn:jsonschema:io:revisium:row-hash-schema:1.0.0',\n RowSchemaHash = 'urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0',\n File = 'urn:jsonschema:io:revisium:file-schema:1.0.0',\n}\n","export enum CustomSchemeKeywords {\n ForeignKey = 'foreignKey',\n}\n\nexport * from './system-schema-ids.js';\n"]}