digital-objects 1.0.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 (87) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +25 -0
  3. package/LICENSE +21 -0
  4. package/README.md +476 -0
  5. package/dist/ai-database-adapter.d.ts +49 -0
  6. package/dist/ai-database-adapter.d.ts.map +1 -0
  7. package/dist/ai-database-adapter.js +89 -0
  8. package/dist/ai-database-adapter.js.map +1 -0
  9. package/dist/errors.d.ts +47 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +72 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/http-schemas.d.ts +165 -0
  14. package/dist/http-schemas.d.ts.map +1 -0
  15. package/dist/http-schemas.js +55 -0
  16. package/dist/http-schemas.js.map +1 -0
  17. package/dist/index.d.ts +29 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +32 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/linguistic.d.ts +54 -0
  22. package/dist/linguistic.d.ts.map +1 -0
  23. package/dist/linguistic.js +226 -0
  24. package/dist/linguistic.js.map +1 -0
  25. package/dist/memory-provider.d.ts +46 -0
  26. package/dist/memory-provider.d.ts.map +1 -0
  27. package/dist/memory-provider.js +279 -0
  28. package/dist/memory-provider.js.map +1 -0
  29. package/dist/ns-client.d.ts +88 -0
  30. package/dist/ns-client.d.ts.map +1 -0
  31. package/dist/ns-client.js +253 -0
  32. package/dist/ns-client.js.map +1 -0
  33. package/dist/ns-exports.d.ts +23 -0
  34. package/dist/ns-exports.d.ts.map +1 -0
  35. package/dist/ns-exports.js +21 -0
  36. package/dist/ns-exports.js.map +1 -0
  37. package/dist/ns.d.ts +60 -0
  38. package/dist/ns.d.ts.map +1 -0
  39. package/dist/ns.js +818 -0
  40. package/dist/ns.js.map +1 -0
  41. package/dist/r2-persistence.d.ts +112 -0
  42. package/dist/r2-persistence.d.ts.map +1 -0
  43. package/dist/r2-persistence.js +252 -0
  44. package/dist/r2-persistence.js.map +1 -0
  45. package/dist/schema-validation.d.ts +80 -0
  46. package/dist/schema-validation.d.ts.map +1 -0
  47. package/dist/schema-validation.js +233 -0
  48. package/dist/schema-validation.js.map +1 -0
  49. package/dist/types.d.ts +184 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +26 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +55 -0
  54. package/src/ai-database-adapter.test.ts +610 -0
  55. package/src/ai-database-adapter.ts +189 -0
  56. package/src/benchmark.test.ts +109 -0
  57. package/src/errors.ts +91 -0
  58. package/src/http-schemas.ts +67 -0
  59. package/src/index.ts +87 -0
  60. package/src/linguistic.test.ts +1107 -0
  61. package/src/linguistic.ts +253 -0
  62. package/src/memory-provider.ts +470 -0
  63. package/src/ns-client.test.ts +1360 -0
  64. package/src/ns-client.ts +342 -0
  65. package/src/ns-exports.ts +23 -0
  66. package/src/ns.test.ts +1381 -0
  67. package/src/ns.ts +1215 -0
  68. package/src/provider.test.ts +675 -0
  69. package/src/r2-persistence.test.ts +263 -0
  70. package/src/r2-persistence.ts +367 -0
  71. package/src/schema-validation.test.ts +167 -0
  72. package/src/schema-validation.ts +330 -0
  73. package/src/types.ts +252 -0
  74. package/test/action-status.test.ts +42 -0
  75. package/test/batch-limits.test.ts +165 -0
  76. package/test/docs.test.ts +48 -0
  77. package/test/errors.test.ts +148 -0
  78. package/test/http-validation.test.ts +401 -0
  79. package/test/ns-client-errors.test.ts +208 -0
  80. package/test/ns-namespace.test.ts +307 -0
  81. package/test/performance.test.ts +168 -0
  82. package/test/schema-validation-error.test.ts +213 -0
  83. package/test/schema-validation.test.ts +440 -0
  84. package/test/search-escaping.test.ts +359 -0
  85. package/test/security.test.ts +322 -0
  86. package/tsconfig.json +10 -0
  87. package/wrangler.jsonc +16 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Standardized error classes for digital-objects
3
+ *
4
+ * These errors provide consistent error handling across all providers
5
+ * (MemoryProvider, NS Durable Object) with proper HTTP status codes.
6
+ */
7
+ /**
8
+ * Base error class for all digital-objects errors
9
+ */
10
+ export declare class DigitalObjectsError extends Error {
11
+ code: string;
12
+ statusCode: number;
13
+ constructor(message: string, code: string, statusCode?: number);
14
+ }
15
+ /**
16
+ * Thrown when a resource is not found
17
+ */
18
+ export declare class NotFoundError extends DigitalObjectsError {
19
+ constructor(type: string, id: string);
20
+ }
21
+ /**
22
+ * Thrown when validation fails
23
+ */
24
+ export declare class ValidationError extends DigitalObjectsError {
25
+ errors: Array<{
26
+ field: string;
27
+ message: string;
28
+ }>;
29
+ constructor(message: string, errors: Array<{
30
+ field: string;
31
+ message: string;
32
+ }>);
33
+ }
34
+ /**
35
+ * Thrown when there's a conflict (e.g., duplicate ID)
36
+ */
37
+ export declare class ConflictError extends DigitalObjectsError {
38
+ constructor(message: string);
39
+ }
40
+ /**
41
+ * Convert an error to an HTTP-safe JSON response body
42
+ */
43
+ export declare function errorToResponse(error: unknown): {
44
+ body: object;
45
+ status: number;
46
+ };
47
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAGnC,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,MAAM;gBAFzB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,MAAY;CAKlC;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,mBAAmB;gBACxC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAIrC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,mBAAmB;IAClB,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;gBAAzE,OAAO,EAAE,MAAM,EAAS,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAItF;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,mBAAmB;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAoBhF"}
package/dist/errors.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Standardized error classes for digital-objects
3
+ *
4
+ * These errors provide consistent error handling across all providers
5
+ * (MemoryProvider, NS Durable Object) with proper HTTP status codes.
6
+ */
7
+ /**
8
+ * Base error class for all digital-objects errors
9
+ */
10
+ export class DigitalObjectsError extends Error {
11
+ code;
12
+ statusCode;
13
+ constructor(message, code, statusCode = 500) {
14
+ super(message);
15
+ this.code = code;
16
+ this.statusCode = statusCode;
17
+ this.name = 'DigitalObjectsError';
18
+ }
19
+ }
20
+ /**
21
+ * Thrown when a resource is not found
22
+ */
23
+ export class NotFoundError extends DigitalObjectsError {
24
+ constructor(type, id) {
25
+ super(`${type} not found: ${id}`, 'NOT_FOUND', 404);
26
+ this.name = 'NotFoundError';
27
+ }
28
+ }
29
+ /**
30
+ * Thrown when validation fails
31
+ */
32
+ export class ValidationError extends DigitalObjectsError {
33
+ errors;
34
+ constructor(message, errors) {
35
+ super(message, 'VALIDATION_ERROR', 400);
36
+ this.errors = errors;
37
+ this.name = 'ValidationError';
38
+ }
39
+ }
40
+ /**
41
+ * Thrown when there's a conflict (e.g., duplicate ID)
42
+ */
43
+ export class ConflictError extends DigitalObjectsError {
44
+ constructor(message) {
45
+ super(message, 'CONFLICT', 409);
46
+ this.name = 'ConflictError';
47
+ }
48
+ }
49
+ /**
50
+ * Convert an error to an HTTP-safe JSON response body
51
+ */
52
+ export function errorToResponse(error) {
53
+ if (error instanceof DigitalObjectsError) {
54
+ return {
55
+ body: {
56
+ error: error.code,
57
+ message: error.message,
58
+ ...(error instanceof ValidationError ? { errors: error.errors } : {}),
59
+ },
60
+ status: error.statusCode,
61
+ };
62
+ }
63
+ // Don't expose internal error details to clients
64
+ return {
65
+ body: {
66
+ error: 'INTERNAL_ERROR',
67
+ message: 'An internal error occurred',
68
+ },
69
+ status: 500,
70
+ };
71
+ }
72
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAGnC;IACA;IAHT,YACE,OAAe,EACR,IAAY,EACZ,aAAqB,GAAG;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAc;QAG/B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,mBAAmB;IACpD,YAAY,IAAY,EAAE,EAAU;QAClC,KAAK,CAAC,GAAG,IAAI,eAAe,EAAE,EAAE,EAAE,WAAW,EAAE,GAAG,CAAC,CAAA;QACnD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,mBAAmB;IAClB;IAApC,YAAY,OAAe,EAAS,MAAiD;QACnF,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAA;QADL,WAAM,GAAN,MAAM,CAA2C;QAEnF,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,mBAAmB;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;QAC/B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;QACzC,OAAO;YACL,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,GAAG,CAAC,KAAK,YAAY,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtE;YACD,MAAM,EAAE,KAAK,CAAC,UAAU;SACzB,CAAA;IACH,CAAC;IAED,iDAAiD;IACjD,OAAO;QACL,IAAI,EAAE;YACJ,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,4BAA4B;SACtC;QACD,MAAM,EAAE,GAAG;KACZ,CAAA;AACH,CAAC"}
@@ -0,0 +1,165 @@
1
+ import { z } from 'zod';
2
+ export declare const NounDefinitionSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ singular: z.ZodOptional<z.ZodString>;
5
+ plural: z.ZodOptional<z.ZodString>;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ name: string;
10
+ singular?: string | undefined;
11
+ plural?: string | undefined;
12
+ description?: string | undefined;
13
+ schema?: Record<string, any> | undefined;
14
+ }, {
15
+ name: string;
16
+ singular?: string | undefined;
17
+ plural?: string | undefined;
18
+ description?: string | undefined;
19
+ schema?: Record<string, any> | undefined;
20
+ }>;
21
+ export declare const VerbDefinitionSchema: z.ZodObject<{
22
+ name: z.ZodString;
23
+ action: z.ZodOptional<z.ZodString>;
24
+ act: z.ZodOptional<z.ZodString>;
25
+ activity: z.ZodOptional<z.ZodString>;
26
+ event: z.ZodOptional<z.ZodString>;
27
+ reverseBy: z.ZodOptional<z.ZodString>;
28
+ inverse: z.ZodOptional<z.ZodString>;
29
+ description: z.ZodOptional<z.ZodString>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ name: string;
32
+ description?: string | undefined;
33
+ action?: string | undefined;
34
+ act?: string | undefined;
35
+ activity?: string | undefined;
36
+ event?: string | undefined;
37
+ reverseBy?: string | undefined;
38
+ inverse?: string | undefined;
39
+ }, {
40
+ name: string;
41
+ description?: string | undefined;
42
+ action?: string | undefined;
43
+ act?: string | undefined;
44
+ activity?: string | undefined;
45
+ event?: string | undefined;
46
+ reverseBy?: string | undefined;
47
+ inverse?: string | undefined;
48
+ }>;
49
+ export declare const CreateThingSchema: z.ZodObject<{
50
+ noun: z.ZodString;
51
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
52
+ id: z.ZodOptional<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ data: Record<string, any>;
55
+ noun: string;
56
+ id?: string | undefined;
57
+ }, {
58
+ data: Record<string, any>;
59
+ noun: string;
60
+ id?: string | undefined;
61
+ }>;
62
+ export declare const UpdateThingSchema: z.ZodObject<{
63
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
64
+ }, "strip", z.ZodTypeAny, {
65
+ data: Record<string, any>;
66
+ }, {
67
+ data: Record<string, any>;
68
+ }>;
69
+ export declare const PerformActionSchema: z.ZodObject<{
70
+ verb: z.ZodString;
71
+ subject: z.ZodOptional<z.ZodString>;
72
+ object: z.ZodOptional<z.ZodString>;
73
+ data: z.ZodOptional<z.ZodAny>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ verb: string;
76
+ object?: string | undefined;
77
+ subject?: string | undefined;
78
+ data?: any;
79
+ }, {
80
+ verb: string;
81
+ object?: string | undefined;
82
+ subject?: string | undefined;
83
+ data?: any;
84
+ }>;
85
+ export declare const BatchCreateThingsSchema: z.ZodObject<{
86
+ noun: z.ZodString;
87
+ items: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>, "many">;
88
+ }, "strip", z.ZodTypeAny, {
89
+ noun: string;
90
+ items: Record<string, any>[];
91
+ }, {
92
+ noun: string;
93
+ items: Record<string, any>[];
94
+ }>;
95
+ export declare const BatchUpdateThingsSchema: z.ZodObject<{
96
+ updates: z.ZodArray<z.ZodObject<{
97
+ id: z.ZodString;
98
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ data: Record<string, any>;
101
+ id: string;
102
+ }, {
103
+ data: Record<string, any>;
104
+ id: string;
105
+ }>, "many">;
106
+ }, "strip", z.ZodTypeAny, {
107
+ updates: {
108
+ data: Record<string, any>;
109
+ id: string;
110
+ }[];
111
+ }, {
112
+ updates: {
113
+ data: Record<string, any>;
114
+ id: string;
115
+ }[];
116
+ }>;
117
+ export declare const BatchDeleteThingsSchema: z.ZodObject<{
118
+ ids: z.ZodArray<z.ZodString, "many">;
119
+ }, "strip", z.ZodTypeAny, {
120
+ ids: string[];
121
+ }, {
122
+ ids: string[];
123
+ }>;
124
+ export declare const BatchPerformActionsSchema: z.ZodObject<{
125
+ actions: z.ZodArray<z.ZodObject<{
126
+ verb: z.ZodString;
127
+ subject: z.ZodOptional<z.ZodString>;
128
+ object: z.ZodOptional<z.ZodString>;
129
+ data: z.ZodOptional<z.ZodAny>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ verb: string;
132
+ object?: string | undefined;
133
+ subject?: string | undefined;
134
+ data?: any;
135
+ }, {
136
+ verb: string;
137
+ object?: string | undefined;
138
+ subject?: string | undefined;
139
+ data?: any;
140
+ }>, "many">;
141
+ }, "strip", z.ZodTypeAny, {
142
+ actions: {
143
+ verb: string;
144
+ object?: string | undefined;
145
+ subject?: string | undefined;
146
+ data?: any;
147
+ }[];
148
+ }, {
149
+ actions: {
150
+ verb: string;
151
+ object?: string | undefined;
152
+ subject?: string | undefined;
153
+ data?: any;
154
+ }[];
155
+ }>;
156
+ export type NounDefinitionInput = z.infer<typeof NounDefinitionSchema>;
157
+ export type VerbDefinitionInput = z.infer<typeof VerbDefinitionSchema>;
158
+ export type CreateThingInput = z.infer<typeof CreateThingSchema>;
159
+ export type UpdateThingInput = z.infer<typeof UpdateThingSchema>;
160
+ export type PerformActionInput = z.infer<typeof PerformActionSchema>;
161
+ export type BatchCreateThingsInput = z.infer<typeof BatchCreateThingsSchema>;
162
+ export type BatchUpdateThingsInput = z.infer<typeof BatchUpdateThingsSchema>;
163
+ export type BatchDeleteThingsInput = z.infer<typeof BatchDeleteThingsSchema>;
164
+ export type BatchPerformActionsInput = z.infer<typeof BatchPerformActionsSchema>;
165
+ //# sourceMappingURL=http-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-schemas.d.ts","sourceRoot":"","sources":["../src/http-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;EAM/B,CAAA;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS/B,CAAA;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;EAI5B,CAAA;AAEF,eAAO,MAAM,iBAAiB;;;;;;EAE5B,CAAA;AAEF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;EAK9B,CAAA;AAGF,eAAO,MAAM,uBAAuB;;;;;;;;;EAGlC,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;EAOlC,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAA;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASpC,CAAA;AAGF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AACtE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AACtE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAChE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAChE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AACpE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ export const NounDefinitionSchema = z.object({
3
+ name: z.string().min(1),
4
+ singular: z.string().optional(),
5
+ plural: z.string().optional(),
6
+ description: z.string().optional(),
7
+ schema: z.record(z.any()).optional(),
8
+ });
9
+ export const VerbDefinitionSchema = z.object({
10
+ name: z.string().min(1),
11
+ action: z.string().optional(),
12
+ act: z.string().optional(),
13
+ activity: z.string().optional(),
14
+ event: z.string().optional(),
15
+ reverseBy: z.string().optional(),
16
+ inverse: z.string().optional(),
17
+ description: z.string().optional(),
18
+ });
19
+ export const CreateThingSchema = z.object({
20
+ noun: z.string().min(1),
21
+ data: z.record(z.any()),
22
+ id: z.string().optional(),
23
+ });
24
+ export const UpdateThingSchema = z.object({
25
+ data: z.record(z.any()),
26
+ });
27
+ export const PerformActionSchema = z.object({
28
+ verb: z.string().min(1),
29
+ subject: z.string().optional(),
30
+ object: z.string().optional(),
31
+ data: z.any().optional(),
32
+ });
33
+ // Batch operation schemas
34
+ export const BatchCreateThingsSchema = z.object({
35
+ noun: z.string().min(1),
36
+ items: z.array(z.record(z.any())),
37
+ });
38
+ export const BatchUpdateThingsSchema = z.object({
39
+ updates: z.array(z.object({
40
+ id: z.string().min(1),
41
+ data: z.record(z.any()),
42
+ })),
43
+ });
44
+ export const BatchDeleteThingsSchema = z.object({
45
+ ids: z.array(z.string().min(1)),
46
+ });
47
+ export const BatchPerformActionsSchema = z.object({
48
+ actions: z.array(z.object({
49
+ verb: z.string().min(1),
50
+ subject: z.string().optional(),
51
+ object: z.string().optional(),
52
+ data: z.any().optional(),
53
+ })),
54
+ });
55
+ //# sourceMappingURL=http-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-schemas.js","sourceRoot":"","sources":["../src/http-schemas.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * digital-objects - Unified storage primitive for AI primitives
3
+ *
4
+ * Core concepts:
5
+ * - **Nouns**: Entity type definitions (singular/plural/schema)
6
+ * - **Verbs**: Action definitions (conjugations, reverse forms)
7
+ * - **Things**: Entity instances (the actual data)
8
+ * - **Actions**: Events + Relationships + Audit Trail (unified graph edges)
9
+ *
10
+ * Providers:
11
+ * - `MemoryProvider`: In-memory for tests
12
+ * - `NS`: SQLite in Cloudflare Durable Objects (import from 'digital-objects/ns')
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ export type { Noun, NounDefinition, Verb, VerbDefinition, Thing, Action, ActionStatus, FieldDefinition, PrimitiveType, ListOptions, ActionOptions, DigitalObjectsProvider, Direction, } from './types.js';
17
+ export { validateDirection } from './types.js';
18
+ export { MemoryProvider, createMemoryProvider } from './memory-provider.js';
19
+ export { deriveNoun, deriveVerb, pluralize, singularize } from './linguistic.js';
20
+ export { NSClient, createNSClient } from './ns-client.js';
21
+ export type { NSClientOptions } from './ns-client.js';
22
+ export { createSnapshot, restoreSnapshot, appendWAL, replayWAL, compactWAL, exportJSONL, importJSONL, exportToR2, importFromR2, } from './r2-persistence.js';
23
+ export type { Snapshot, WALEntry, SnapshotOptions, SnapshotResult } from './r2-persistence.js';
24
+ export { createDBProviderAdapter } from './ai-database-adapter.js';
25
+ export type { DBProvider, ListOptions as DBListOptions, SearchOptions, SemanticSearchOptions, HybridSearchOptions, } from './ai-database-adapter.js';
26
+ export { DigitalObjectsError, NotFoundError, ValidationError, ConflictError, errorToResponse, } from './errors.js';
27
+ export { validateOnly, validateData } from './schema-validation.js';
28
+ export type { SchemaValidationError, ValidationErrorCode, ValidationResult, ValidationOptions, } from './schema-validation.js';
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,YAAY,EACV,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,cAAc,EACd,KAAK,EACL,MAAM,EACN,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,SAAS,GACV,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAG9C,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAG3E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGhF,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACzD,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGrD,OAAO,EACL,cAAc,EACd,eAAe,EACf,SAAS,EACT,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAG9F,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,YAAY,EACV,UAAU,EACV,WAAW,IAAI,aAAa,EAC5B,aAAa,EACb,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,aAAa,CAAA;AAGpB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACnE,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,wBAAwB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * digital-objects - Unified storage primitive for AI primitives
3
+ *
4
+ * Core concepts:
5
+ * - **Nouns**: Entity type definitions (singular/plural/schema)
6
+ * - **Verbs**: Action definitions (conjugations, reverse forms)
7
+ * - **Things**: Entity instances (the actual data)
8
+ * - **Actions**: Events + Relationships + Audit Trail (unified graph edges)
9
+ *
10
+ * Providers:
11
+ * - `MemoryProvider`: In-memory for tests
12
+ * - `NS`: SQLite in Cloudflare Durable Objects (import from 'digital-objects/ns')
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ // Validation utilities
17
+ export { validateDirection } from './types.js';
18
+ // Memory Provider
19
+ export { MemoryProvider, createMemoryProvider } from './memory-provider.js';
20
+ // Linguistic utilities
21
+ export { deriveNoun, deriveVerb, pluralize, singularize } from './linguistic.js';
22
+ // NS Client (for HTTP access to NS Durable Object)
23
+ export { NSClient, createNSClient } from './ns-client.js';
24
+ // R2 Persistence (backup/restore to Cloudflare R2)
25
+ export { createSnapshot, restoreSnapshot, appendWAL, replayWAL, compactWAL, exportJSONL, importJSONL, exportToR2, importFromR2, } from './r2-persistence.js';
26
+ // ai-database Adapter
27
+ export { createDBProviderAdapter } from './ai-database-adapter.js';
28
+ // Errors
29
+ export { DigitalObjectsError, NotFoundError, ValidationError, ConflictError, errorToResponse, } from './errors.js';
30
+ // Schema Validation
31
+ export { validateOnly, validateData } from './schema-validation.js';
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,uBAAuB;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE3E,uBAAuB;AACvB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEhF,mDAAmD;AACnD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAGzD,mDAAmD;AACnD,OAAO,EACL,cAAc,EACd,eAAe,EACf,SAAS,EACT,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,GACb,MAAM,qBAAqB,CAAA;AAG5B,sBAAsB;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AASlE,SAAS;AACT,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,aAAa,CAAA;AAEpB,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Linguistic utilities for auto-deriving noun and verb forms
3
+ */
4
+ /**
5
+ * Derive noun forms from a PascalCase name
6
+ *
7
+ * @example
8
+ * deriveNoun('Post') => { singular: 'post', plural: 'posts', slug: 'post' }
9
+ * deriveNoun('BlogPost') => { singular: 'blog post', plural: 'blog posts', slug: 'blog-post' }
10
+ * deriveNoun('Person') => { singular: 'person', plural: 'persons', slug: 'person' }
11
+ */
12
+ export declare function deriveNoun(name: string): {
13
+ singular: string;
14
+ plural: string;
15
+ slug: string;
16
+ };
17
+ /**
18
+ * Pluralize a word
19
+ *
20
+ * Handles common English pluralization rules:
21
+ * - Words ending in 's', 'x', 'z', 'ch', 'sh' -> add 'es'
22
+ * - Words ending in consonant + 'y' -> replace 'y' with 'ies'
23
+ * - Words ending in 'f' or 'fe' -> replace with 'ves'
24
+ * - Special cases (person->people, child->children, etc.)
25
+ * - Default: add 's'
26
+ */
27
+ export declare function pluralize(word: string): string;
28
+ /**
29
+ * Singularize a word (reverse of pluralize)
30
+ */
31
+ export declare function singularize(word: string): string;
32
+ /**
33
+ * Derive verb conjugations from base form
34
+ *
35
+ * @example
36
+ * deriveVerb('create') => {
37
+ * action: 'create',
38
+ * act: 'creates',
39
+ * activity: 'creating',
40
+ * event: 'created',
41
+ * reverseBy: 'createdBy',
42
+ * reverseAt: 'createdAt'
43
+ * }
44
+ */
45
+ export declare function deriveVerb(name: string): {
46
+ action: string;
47
+ act: string;
48
+ activity: string;
49
+ event: string;
50
+ reverseBy: string;
51
+ reverseAt: string;
52
+ reverseIn: string;
53
+ };
54
+ //# sourceMappingURL=linguistic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linguistic.d.ts","sourceRoot":"","sources":["../src/linguistic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAW3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmD9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoDhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAsFA"}