@docstack/client 0.0.4 → 0.0.5

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 (54) hide show
  1. package/lib/core/attribute.js +406 -0
  2. package/lib/core/attribute.js.map +1 -0
  3. package/lib/core/class.d.ts +14 -15
  4. package/lib/core/class.js +761 -0
  5. package/lib/core/class.js.map +1 -0
  6. package/lib/core/crypto-engine/index.js +229 -0
  7. package/lib/core/crypto-engine/index.js.map +1 -0
  8. package/lib/core/crypto-engine/utils.js +88 -0
  9. package/lib/core/crypto-engine/utils.js.map +1 -0
  10. package/lib/core/datamodel/index.js +1308 -0
  11. package/lib/core/datamodel/index.js.map +1 -0
  12. package/lib/core/domain.d.ts +7 -8
  13. package/lib/core/domain.js +423 -0
  14. package/lib/core/domain.js.map +1 -0
  15. package/lib/core/index.js +520 -0
  16. package/lib/core/index.js.map +1 -0
  17. package/lib/core/job-engine/index.js +220 -0
  18. package/lib/core/job-engine/index.js.map +1 -0
  19. package/lib/core/policy-engine/index.js +232 -0
  20. package/lib/core/policy-engine/index.js.map +1 -0
  21. package/lib/core/query-engine/accumulators.js +258 -0
  22. package/lib/core/query-engine/accumulators.js.map +1 -0
  23. package/lib/core/query-engine/evaluator.js +179 -0
  24. package/lib/core/query-engine/evaluator.js.map +1 -0
  25. package/lib/core/query-engine/executor.js +405 -0
  26. package/lib/core/query-engine/executor.js.map +1 -0
  27. package/lib/core/query-engine/index.js +4 -0
  28. package/lib/core/query-engine/index.js.map +1 -0
  29. package/lib/core/query-engine/parser.js +515 -0
  30. package/lib/core/query-engine/parser.js.map +1 -0
  31. package/lib/core/query-engine/planner.js +330 -0
  32. package/lib/core/query-engine/planner.js.map +1 -0
  33. package/lib/core/stack.js +1817 -0
  34. package/lib/core/stack.js.map +1 -0
  35. package/lib/core/test-utils/docstack.js +222 -0
  36. package/lib/core/test-utils/docstack.js.map +1 -0
  37. package/lib/core/trigger/index.js +81 -0
  38. package/lib/core/trigger/index.js.map +1 -0
  39. package/lib/index.js +10 -4
  40. package/lib/index.js.map +1 -1
  41. package/lib/index.umd.js +10 -4
  42. package/lib/plugins/pouchdb.js +368 -0
  43. package/lib/plugins/pouchdb.js.map +1 -0
  44. package/lib/utils/crypto/index.js +34 -0
  45. package/lib/utils/crypto/index.js.map +1 -0
  46. package/lib/utils/index.js +58 -0
  47. package/lib/utils/index.js.map +1 -0
  48. package/lib/utils/logger/index.js +20 -0
  49. package/lib/utils/logger/index.js.map +1 -0
  50. package/lib/utils/logger/transport.js +28 -0
  51. package/lib/utils/logger/transport.js.map +1 -0
  52. package/lib/workers/dataModel.js +48 -0
  53. package/lib/workers/dataModel.js.map +1 -0
  54. package/package.json +2 -2
@@ -0,0 +1,406 @@
1
+ var _a;
2
+ import z from "zod";
3
+ import { Attribute as Attribute_, ATTRIBUTE_TYPES } from "@docstack/shared";
4
+ /**
5
+ * Represents a single attribute (field) within a Class schema.
6
+ *
7
+ * Attributes define the structure of documents, including their type,
8
+ * validation rules (via Zod), and configuration options like mandatory,
9
+ * default values, primary keys, and foreign key references.
10
+ *
11
+ * Use the static factory method {@link Attribute.create} to instantiate
12
+ * attributes with proper validation and persistence.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Create a string attribute
17
+ * const titleAttr = await Attribute.create(taskClass, 'title', 'string', 'Task Title', {
18
+ * mandatory: true,
19
+ * maxLength: 200
20
+ * });
21
+ *
22
+ * // Create a foreign key reference
23
+ * const assigneeAttr = await Attribute.create(taskClass, 'assigneeId', 'foreign_key', 'Assigned User', {
24
+ * targetClass: 'User'
25
+ * });
26
+ * ```
27
+ *
28
+ * @extends Attribute_
29
+ */
30
+ class Attribute extends Attribute_ {
31
+ /**
32
+ * Creates a new Attribute instance.
33
+ * For most use cases, prefer using {@link Attribute.create} which also persists the attribute.
34
+ *
35
+ * @param classObj - The parent Class for this attribute
36
+ * @param name - The attribute name
37
+ * @param type - The attribute type (e.g., 'string', 'integer', 'boolean', 'enum')
38
+ * @param description - Optional description
39
+ * @param config - Type-specific configuration options
40
+ */
41
+ constructor(classObj = null, name, type, description, config) {
42
+ super(classObj, name, type, config);
43
+ /** Zod schema for runtime validation of this field. */
44
+ this.field = z.any();
45
+ /**
46
+ * Validates that reference-type attributes have proper domain configuration.
47
+ * Called automatically during {@link Attribute.create}.
48
+ * @throws Error if the reference configuration is invalid
49
+ */
50
+ this.ensureReferenceConfigIsValid = async () => {
51
+ if (this.model.type !== "reference") {
52
+ return;
53
+ }
54
+ if (!this.class) {
55
+ throw new Error(`Attribute '${this.name}' must belong to a class to validate reference configuration.`);
56
+ }
57
+ const stack = this.class.getStack();
58
+ if (!stack) {
59
+ throw new Error(`Class '${this.class.getName()}' is not attached to a stack.`);
60
+ }
61
+ const config = this.model.config;
62
+ const domainName = config.domain;
63
+ if (typeof domainName !== "string" || domainName.length === 0) {
64
+ throw new Error(`Attribute '${this.name}' of type 'reference' must declare a domain.`);
65
+ }
66
+ if (config.isArray) {
67
+ throw new Error(`Attribute '${this.name}' of type 'reference' cannot be an array.`);
68
+ }
69
+ const domain = await stack.getDomain(domainName);
70
+ if (!domain) {
71
+ throw new Error(`Domain '${domainName}' was not found for attribute '${this.name}'.`);
72
+ }
73
+ const classId = this.class.id;
74
+ switch (domain.relation) {
75
+ case "1:N":
76
+ if (classId !== domain.targetClass.id) {
77
+ throw new Error(`Given classId '${classId}' Reference attributes for domain '${domainName}' can only be added to class '${domain.targetClass}'.`);
78
+ }
79
+ break;
80
+ case "N:1":
81
+ if (classId !== domain.sourceClass.id) {
82
+ throw new Error(`Given classId '${classId}' Reference attributes for domain '${domainName}' can only be added to class '${domain.sourceClass}'.`);
83
+ }
84
+ break;
85
+ case "1:1":
86
+ if (classId !== domain.sourceClass.id && classId !== domain.targetClass.id) {
87
+ throw new Error(`Class '${classId}' is not part of domain '${domainName}'.`);
88
+ }
89
+ break;
90
+ case "N:N":
91
+ throw new Error(`Domain '${domainName}' does not support reference attributes.`);
92
+ default:
93
+ throw new Error(`Unsupported relation '${domain.relation}' for domain '${domainName}'.`);
94
+ }
95
+ };
96
+ /**
97
+ * Builds the Zod validation schema based on attribute type and configuration.
98
+ * Called automatically during construction.
99
+ */
100
+ this.setField = () => {
101
+ const { name, type, config } = this.model;
102
+ let field;
103
+ switch (type) {
104
+ // ... existing cases for 'string', 'number', 'boolean', 'date' ...
105
+ case 'string':
106
+ field = z.string();
107
+ if (config.maxLength !== undefined) {
108
+ field = field.max(config.maxLength);
109
+ }
110
+ break;
111
+ case 'integer':
112
+ field = z.number();
113
+ if (typeof config.min === 'number') {
114
+ field = field.min(config.min);
115
+ }
116
+ if (typeof config.max === 'number') {
117
+ field = field.max(config.max);
118
+ }
119
+ break;
120
+ // case 'date':
121
+ // field = z.date();
122
+ // break;
123
+ case 'decimal':
124
+ field = z.number();
125
+ // min and max validation
126
+ if (typeof config.min === 'number') {
127
+ field = field.min(config.min);
128
+ }
129
+ if (typeof config.max === 'number') {
130
+ field = field.max(config.max);
131
+ }
132
+ // decimal precision validation (with refinement)
133
+ if (typeof config.precision === 'number' && config.precision >= 0) {
134
+ const isPrecise = (value) => {
135
+ if (typeof value !== 'number')
136
+ return true;
137
+ const valueAsString = value.toString();
138
+ const decimalPart = valueAsString.split('.')[1];
139
+ const decimalPlaces = decimalPart ? decimalPart.length : 0;
140
+ return decimalPlaces <= config.precision;
141
+ };
142
+ field = field.refine(isPrecise, `Number cannot have more than ${config.precision} decimals.`);
143
+ }
144
+ break;
145
+ case 'boolean':
146
+ field = z.boolean();
147
+ break;
148
+ case "object":
149
+ field = z.object({});
150
+ break;
151
+ case 'enum':
152
+ if (!config.values || !Array.isArray(config.values) || config.values.length === 0) {
153
+ throw new Error(`Attribute '${name}' of type 'enum' must have a non-empty 'values' array in its config.`);
154
+ }
155
+ const enumValues = config.values.map(v => v.value);
156
+ field = z.enum(enumValues);
157
+ break;
158
+ case 'foreign_key':
159
+ if (!config.targetClass) {
160
+ throw new Error(`Attribute '${name}' of type 'foreign_key' is missing a 'targetClass' in its config.`);
161
+ }
162
+ const foreignClass = config.targetClass;
163
+ const baseSchema = z.string();
164
+ field = baseSchema.refine(async (documentIdOrIds) => {
165
+ var _b;
166
+ const idsToValidate = Array.isArray(documentIdOrIds) ? documentIdOrIds : [documentIdOrIds];
167
+ if (idsToValidate.length === 0) {
168
+ return true;
169
+ }
170
+ try {
171
+ if (this.class) {
172
+ const stack = this.class.getStack();
173
+ if (stack) {
174
+ const promises = idsToValidate.map(id => stack.db.get(id));
175
+ const fetchResult = await Promise.all(promises);
176
+ return true;
177
+ }
178
+ else
179
+ throw new Error("Missing stack connection");
180
+ }
181
+ else
182
+ throw new Error("Missing class parentship");
183
+ }
184
+ catch (error) {
185
+ if (error.status === 404) {
186
+ console.error(`Foreign key validation failed: document not found in class '${foreignClass}'. ${(_b = this.class) === null || _b === void 0 ? void 0 : _b.getName()}`, { error });
187
+ return false;
188
+ }
189
+ throw error;
190
+ }
191
+ }, {
192
+ message: `One or more documents not found in class '${foreignClass}'.`,
193
+ });
194
+ break;
195
+ case 'reference':
196
+ field = z.string().min(1);
197
+ break;
198
+ default:
199
+ throw new Error(`Unsupported schema type: '${type}' for field '${name}'`);
200
+ }
201
+ // These rules are applied regardless of the type, and in the correct order
202
+ if (config.defaultValue) {
203
+ field = field.default(config.defaultValue);
204
+ }
205
+ if (config.mandatory !== true) {
206
+ field = field.optional();
207
+ }
208
+ if (config.isArray === true) {
209
+ field = z.array(field);
210
+ }
211
+ this.field = field;
212
+ };
213
+ /**
214
+ * Checks if this attribute is marked as a primary key.
215
+ * @returns `true` if this is a primary key attribute
216
+ */
217
+ this.isPrimaryKey = () => {
218
+ let model = this.getModel();
219
+ return !!model.config.primaryKey;
220
+ };
221
+ /**
222
+ * Checks if this attribute is mandatory (required).
223
+ * @returns `true` if the attribute is mandatory
224
+ */
225
+ this.isMandatory = () => {
226
+ return !!this.model.config.mandatory;
227
+ };
228
+ /**
229
+ * Returns the AttributeModel for this attribute.
230
+ * @returns The underlying AttributeModel
231
+ */
232
+ this.getModel = () => {
233
+ return this.model;
234
+ };
235
+ /**
236
+ * Returns the parent Class for this attribute.
237
+ * @returns The Class instance
238
+ * @throws Error if the attribute has no parent class
239
+ */
240
+ this.getClass = () => {
241
+ if (this.class)
242
+ return this.class;
243
+ else
244
+ throw Error("Missing class configuration for this attribute");
245
+ };
246
+ /**
247
+ * Validates a value against this attribute's Zod schema.
248
+ *
249
+ * @param data - The value to validate
250
+ * @returns Zod safe parse result with success status and data/error
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const result = await priceAttr.validate(19.99);
255
+ * if (result.success) {
256
+ * console.log('Valid:', result.data);
257
+ * } else {
258
+ * console.log('Invalid:', result.error);
259
+ * }
260
+ * ```
261
+ */
262
+ this.validate = async (data) => {
263
+ return this.field.safeParseAsync(data);
264
+ };
265
+ this.setModel = (model) => {
266
+ let currentModel = this.getModel();
267
+ model = Object.assign(currentModel || {}, model);
268
+ this.model = model;
269
+ this.defaultValue = model.config.defaultValue;
270
+ };
271
+ // TODO: Better define config
272
+ this.getType = (type) => {
273
+ if (this.checkTypeValidity(type)) {
274
+ return type;
275
+ }
276
+ else
277
+ throw Error("Invalid attribute type: " + type);
278
+ // return this?
279
+ };
280
+ /**
281
+ * Returns an empty/default value for this attribute.
282
+ * Uses the Zod schema's default value if configured.
283
+ * @returns Object with attribute name as key and default/null value
284
+ */
285
+ this.getEmpty = () => {
286
+ const partialDoc = {
287
+ [this.name]: this.field.parse(undefined) || null
288
+ };
289
+ return partialDoc;
290
+ };
291
+ // getType()
292
+ /**
293
+ * Returns the attribute name.
294
+ * @returns The attribute name string
295
+ */
296
+ this.getName = () => {
297
+ return this.name;
298
+ };
299
+ this.checkTypeValidity = (type) => {
300
+ let validity = false;
301
+ if (ATTRIBUTE_TYPES.includes(type)) {
302
+ validity = true;
303
+ }
304
+ return validity;
305
+ };
306
+ // TODO: change to imported const default configs for types
307
+ // as of now it accepts only string
308
+ // TODO: since config depends on attribute's type,
309
+ // find a way to check if given configs are correct
310
+ // find a way to add default configs base on type
311
+ this.getTypeConf = (type, config) => {
312
+ switch (type) {
313
+ // TODO: add missing cases and change values to imported const
314
+ case "decimal":
315
+ config = Object.assign({ max: null, min: null, precision: null, isArray: false }, config);
316
+ break;
317
+ case "integer":
318
+ config = Object.assign({ max: null, min: null, isArray: false }, config);
319
+ break;
320
+ case "string":
321
+ config = Object.assign({ isArray: false }, config);
322
+ break;
323
+ case "object":
324
+ config = Object.assign({ isArray: false }, config);
325
+ break;
326
+ case "date":
327
+ config = Object.assign({ format: "iso", max: null, min: null, isArray: false }, config);
328
+ break;
329
+ case "boolean":
330
+ config = Object.assign({ defaultValue: false, isArray: false }, config);
331
+ break;
332
+ case "foreign_key":
333
+ config = Object.assign({ targetClass: null, isArray: false }, config);
334
+ break;
335
+ case "enum":
336
+ config = Object.assign({ values: [], isArray: false }, config);
337
+ break;
338
+ case "reference":
339
+ config = Object.assign({ isArray: false }, config);
340
+ break;
341
+ default:
342
+ throw new Error("Unexpected type: " + type);
343
+ // return "^[a-zA-Z0-9_\\s]".concat("{0,"+config.maxLength+"}$");
344
+ }
345
+ return config;
346
+ };
347
+ this.name = name;
348
+ this.description = description;
349
+ this.setModel({
350
+ name: this.name,
351
+ description: this.description,
352
+ type: this.getType(type),
353
+ config: this.getTypeConf(type, config) || {},
354
+ });
355
+ this.setField();
356
+ this.class = classObj;
357
+ }
358
+ /**
359
+ * Creates a new Attribute and persists it to the parent Class.
360
+ * This is the primary factory method for creating attributes.
361
+ *
362
+ * @param classObj - The parent Class to add the attribute to
363
+ * @param name - The attribute name
364
+ * @param type - The attribute type
365
+ * @param description - Optional description
366
+ * @param config - Type-specific configuration
367
+ * @returns The created Attribute instance
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const priceAttr = await Attribute.create(productClass, 'price', 'decimal', 'Product price', {
372
+ * min: 0,
373
+ * precision: 2,
374
+ * mandatory: true
375
+ * });
376
+ * ```
377
+ */
378
+ static async create(classObj, name, type, description, config) {
379
+ const attribute = new _a(classObj, name, type, description, config);
380
+ await attribute.ensureReferenceConfigIsValid();
381
+ await _a.build(attribute);
382
+ return attribute;
383
+ }
384
+ }
385
+ _a = Attribute;
386
+ /**
387
+ * Adds an attribute to its parent class and persists to the database.
388
+ * Used internally by {@link Attribute.create}.
389
+ *
390
+ * @param attributeObj - The Attribute instance to build
391
+ * @returns The Attribute instance
392
+ * @throws Error if the class has no stack connection
393
+ */
394
+ Attribute.build = async (attributeObj) => {
395
+ let classObj = attributeObj.getClass();
396
+ let stack = classObj.getStack();
397
+ if (stack) {
398
+ await classObj.addAttribute(attributeObj);
399
+ return attributeObj;
400
+ }
401
+ else {
402
+ throw new Error("Missing db configuration");
403
+ }
404
+ };
405
+ export default Attribute;
406
+ //# sourceMappingURL=attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/core/attribute.ts"],"names":[],"mappings":";AAAA,OAAO,CAAmC,MAAM,KAAK,CAAC;AAEtD,OAAO,EAAE,SAAS,IAAI,UAAU,EAAiC,eAAe,EAA+C,MAAM,kBAAkB,CAAC;AAExJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,SAAU,SAAQ,UAAU;IAc9B;;;;;;;;;OASG;IACH,YAAY,WAAyB,IAAI,EAAE,IAAY,EAAE,IAA2B,EAAE,WAAoB,EAAE,MAAgC;QACxI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAlBxC,uDAAuD;QACvD,UAAK,GAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;QA8BrB;;;;WAIG;QACH,iCAA4B,GAAG,KAAK,IAAI,EAAE;YACtC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAClC,OAAO;YACX,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,cAAc,IAA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QAAQ,EAAE,CAAC;IAChC,IAAI,KAAK,EAAE,CAAC;QACR,MAAM,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,YAAY,CAAC;IACxB,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAChD,CAAC;AACL,CAAC,AATW,CASX;AA0FL,eAAe,SAAS,CAAC"}
@@ -1,10 +1,9 @@
1
1
  import { Class as Class_, TriggerModel } from "@docstack/shared";
2
- import { ClassModel, AttributeModel, Document } from "@docstack/shared";
2
+ import { Stack, ClassModel, Attribute as Attribute_, AttributeModel, Document } from "@docstack/shared";
3
3
  import Attribute from "./attribute";
4
4
  import { Logger } from 'winston';
5
5
  import { Trigger } from "./trigger/index";
6
6
  import { z } from "zod";
7
- import ClientStack from "./stack";
8
7
  /**
9
8
  * Represents a data class (schema definition) in the DocStack database.
10
9
  *
@@ -31,7 +30,7 @@ import ClientStack from "./stack";
31
30
  */
32
31
  declare class Class extends Class_ {
33
32
  /** Reference to the parent stack instance. */
34
- stack: ClientStack | undefined;
33
+ stack: Stack | undefined;
35
34
  /** The name of this class (e.g., 'Task', 'User'). */
36
35
  name: string;
37
36
  /** The class type (e.g., 'class', '~self'). */
@@ -58,7 +57,7 @@ declare class Class extends Class_ {
58
57
  triggers: Trigger[];
59
58
  private constructor();
60
59
  build: () => Promise<Class>;
61
- init: (stack: ClientStack | null, id: string, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => void;
60
+ init: (stack: Stack | null, id: string, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => void;
62
61
  /**
63
62
  * Gets a Class instance without persisting it to the database.
64
63
  * Use this for working with existing class models or for testing.
@@ -72,7 +71,7 @@ declare class Class extends Class_ {
72
71
  * @param schema - Initial schema definition
73
72
  * @returns A new Class instance (not persisted)
74
73
  */
75
- static get: (stack: ClientStack, id: string, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => Class;
74
+ static get: (stack: Stack, id: string, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => Class;
76
75
  /**
77
76
  * Creates a new class and persists it to the database.
78
77
  * This is the primary factory method for creating new classes.
@@ -89,7 +88,7 @@ declare class Class extends Class_ {
89
88
  * const userClass = await Class.create(stack, 'User', 'class', 'Application users');
90
89
  * ```
91
90
  */
92
- static create: (stack: ClientStack, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => Promise<Class>;
91
+ static create: (stack: Stack, name: string, type: ClassModel["~class"], description?: string, schema?: ClassModel["schema"]) => Promise<Class>;
93
92
  /**
94
93
  * Builds a Class instance from an existing ClassModel document.
95
94
  * Hydrates attributes and triggers from the model.
@@ -98,7 +97,7 @@ declare class Class extends Class_ {
98
97
  * @param classModel - The ClassModel document from the database
99
98
  * @returns The hydrated Class instance
100
99
  */
101
- static buildFromModel: (stack: ClientStack, classModel: ClassModel) => Promise<Class>;
100
+ static buildFromModel: (stack: Stack, classModel: ClassModel) => Promise<Class>;
102
101
  /**
103
102
  * Fetches a class by its document ID.
104
103
  *
@@ -107,7 +106,7 @@ declare class Class extends Class_ {
107
106
  * @returns The Class instance
108
107
  * @throws Error if the class is not found
109
108
  */
110
- static fetchById: (stack: ClientStack, classId: string) => Promise<Class>;
109
+ static fetchById: (stack: Stack, classId: string) => Promise<Class>;
111
110
  /**
112
111
  * Fetches a class by its name.
113
112
  * This is the most common way to retrieve an existing class.
@@ -124,7 +123,7 @@ declare class Class extends Class_ {
124
123
  * }
125
124
  * ```
126
125
  */
127
- static fetch: (stack: ClientStack, className: string) => Promise<Class>;
126
+ static fetch: (stack: Stack, className: string) => Promise<Class>;
128
127
  uniqueCheck: (doc: Document) => Promise<boolean>;
129
128
  bulkUniqueCheck: (pKs: string[]) => Promise<boolean>;
130
129
  /**
@@ -138,10 +137,10 @@ declare class Class extends Class_ {
138
137
  }) => Promise<boolean>;
139
138
  setId: (id: string) => void;
140
139
  getName: () => string;
141
- getStack: () => ClientStack;
142
- getDescription: () => string;
143
- getType: () => "~self" | "class";
144
- getId: () => string;
140
+ getStack: () => Stack | undefined;
141
+ getDescription: () => string | undefined;
142
+ getType: () => "class" | "~self";
143
+ getId: () => string | undefined;
145
144
  /**
146
145
  * Builds the schema object from the current attributes.
147
146
  * @returns The schema definition object
@@ -184,7 +183,7 @@ declare class Class extends Class_ {
184
183
  * // Or use Attribute.create() for a simpler API
185
184
  * ```
186
185
  */
187
- addAttribute: (attribute: Attribute | AttributeModel) => Promise<Class>;
186
+ addAttribute: (attribute: Attribute_ | AttributeModel) => Promise<Class>;
188
187
  /**
189
188
  * Modifies an existing attribute in the class schema.
190
189
  *
@@ -192,7 +191,7 @@ declare class Class extends Class_ {
192
191
  * @param attribute - The new Attribute or AttributeModel definition
193
192
  * @returns This Class instance for chaining
194
193
  */
195
- modifyAttribute: (name: string, attribute: Attribute | AttributeModel) => Promise<Class>;
194
+ modifyAttribute: (name: string, attribute: Attribute_ | AttributeModel) => Promise<Class>;
196
195
  /**
197
196
  * Removes an attribute from the class schema.
198
197
  *