@arcote.tech/arc 0.1.8 → 0.1.9

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 (55) hide show
  1. package/dist/context/context.d.ts +1 -0
  2. package/dist/context/element.d.ts +21 -1
  3. package/dist/context/event.d.ts +2 -1
  4. package/dist/context/query-builders.d.ts +1 -0
  5. package/dist/data-storage/data-storage-master.d.ts +2 -0
  6. package/dist/database/database-mappers.d.ts +39 -0
  7. package/dist/database/database-store.d.ts +58 -0
  8. package/dist/database/index.d.ts +3 -0
  9. package/dist/database/schema-extraction.d.ts +12 -0
  10. package/dist/db/index.d.ts +1 -0
  11. package/dist/db/interface.d.ts +1 -0
  12. package/dist/db/postgresAdapter.d.ts +90 -0
  13. package/dist/db/sqliteAdapter.d.ts +47 -3
  14. package/dist/elements/abstract.d.ts +28 -0
  15. package/dist/elements/any.d.ts +2 -0
  16. package/dist/elements/array.d.ts +3 -0
  17. package/dist/elements/blob.d.ts +2 -0
  18. package/dist/elements/boolean.d.ts +3 -0
  19. package/dist/elements/branded.d.ts +2 -0
  20. package/dist/elements/date.d.ts +3 -0
  21. package/dist/elements/default.d.ts +2 -0
  22. package/dist/elements/file.d.ts +2 -0
  23. package/dist/elements/number.d.ts +3 -0
  24. package/dist/elements/object.d.ts +5 -0
  25. package/dist/elements/optional.d.ts +2 -0
  26. package/dist/elements/or.d.ts +2 -0
  27. package/dist/elements/record.d.ts +2 -0
  28. package/dist/elements/string-enum.d.ts +2 -0
  29. package/dist/elements/string.d.ts +3 -0
  30. package/dist/index.d.ts +0 -1
  31. package/dist/index.js +1571 -657
  32. package/dist/telemetry/context.d.ts +65 -0
  33. package/dist/telemetry/index.d.ts +47 -0
  34. package/dist/telemetry/interfaces.d.ts +84 -0
  35. package/dist/telemetry/logger.d.ts +67 -0
  36. package/dist/telemetry/no-op.d.ts +54 -0
  37. package/dist/telemetry/tracer.d.ts +85 -0
  38. package/dist/utils.d.ts +0 -19
  39. package/dist/view/view.d.ts +5 -3
  40. package/package.json +1 -1
  41. package/dist/collection/collection.d.ts +0 -81
  42. package/dist/collection/index.d.ts +0 -4
  43. package/dist/collection/queries/abstract-collection-query.d.ts +0 -14
  44. package/dist/collection/queries/find.d.ts +0 -29
  45. package/dist/collection/queries/one-item.d.ts +0 -2
  46. package/dist/collection/queries/util.d.ts +0 -3
  47. package/dist/collection/query-builders/find-by-id.d.ts +0 -2
  48. package/dist/collection/query-builders/find-one.d.ts +0 -2
  49. package/dist/collection/query-builders/find.d.ts +0 -13
  50. package/dist/context/simple-query.d.ts +0 -33
  51. package/dist/data-storage/data-storage-builder.d.ts +0 -16
  52. package/dist/data-storage/query-processor.d.ts +0 -22
  53. package/dist/data-storage/store-state-authorized.d.ts +0 -26
  54. package/dist/utils/arcObjectToStoreSchema.d.ts +0 -4
  55. package/dist/utils/index.d.ts +0 -2
@@ -0,0 +1,65 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import type { AuthContext } from '../context/element';
3
+ import { ArcLogger } from './logger';
4
+ /**
5
+ * Extended context that includes telemetry capabilities
6
+ */
7
+ export interface ArcTelemetryContext {
8
+ /**
9
+ * Log a message with automatic trace context
10
+ */
11
+ log: ArcLogger;
12
+ /**
13
+ * Create a child span for a specific operation
14
+ */
15
+ startSpan(name: string, attributes?: Record<string, string | number | boolean>): Span;
16
+ /**
17
+ * Execute a function within a new span
18
+ */
19
+ withSpan<T>(name: string, fn: (span: Span) => Promise<T> | T, attributes?: Record<string, string | number | boolean>): Promise<T>;
20
+ /**
21
+ * Add attributes to the current span
22
+ */
23
+ addSpanAttributes(attributes: Record<string, string | number | boolean>): void;
24
+ /**
25
+ * Add an event to the current span
26
+ */
27
+ addSpanEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
28
+ /**
29
+ * Record an exception in the current span
30
+ */
31
+ recordException(error: Error | string): void;
32
+ /**
33
+ * Get the current trace ID
34
+ */
35
+ getTraceId(): string | undefined;
36
+ /**
37
+ * Get the current span ID
38
+ */
39
+ getSpanId(): string | undefined;
40
+ }
41
+ /**
42
+ * Create telemetry context for command/event handlers
43
+ */
44
+ export declare function createTelemetryContext(authContext: AuthContext, operationType: 'command' | 'event' | 'listener' | 'view', operationName: string): ArcTelemetryContext;
45
+ /**
46
+ * Extract trace context from headers (for HTTP requests)
47
+ */
48
+ export declare function extractTraceContext(headers: Record<string, string | string[] | undefined>): import("@opentelemetry/api").Context;
49
+ /**
50
+ * Inject trace context into headers (for outgoing HTTP requests)
51
+ */
52
+ export declare function injectTraceContext(headers?: Record<string, string>): Record<string, string>;
53
+ /**
54
+ * Run a function with extracted trace context
55
+ */
56
+ export declare function withExtractedContext<T>(headers: Record<string, string | string[] | undefined>, fn: () => T): T;
57
+ /**
58
+ * Get telemetry information from current context
59
+ */
60
+ export declare function getCurrentTelemetryInfo(): {
61
+ traceId: string | undefined;
62
+ spanId: string | undefined;
63
+ isRecording: boolean;
64
+ };
65
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,47 @@
1
+ export type { TelemetryProvider, TelemetryContext, Logger, SpanOptions, DatabaseTelemetry } from './interfaces';
2
+ export { NoOpLogger, NoOpTelemetryContext, NoOpTelemetryProvider, NoOpDatabaseTelemetry, noOpTelemetryProvider, noOpDatabaseTelemetry, } from './no-op';
3
+ export declare const initializeTelemetry: (...args: any[]) => never;
4
+ export declare const getTelemetry: () => null;
5
+ export declare const startSpan: (...args: any[]) => never;
6
+ export declare const withSpan: (...args: any[]) => never;
7
+ export declare const ArcTelemetry: {
8
+ new (): {};
9
+ };
10
+ export declare const initializeLogger: (...args: any[]) => never;
11
+ export declare const getLogger: () => never;
12
+ export declare const ArcLogger: {
13
+ new (): {};
14
+ };
15
+ export declare const createTelemetryContext: (...args: any[]) => never;
16
+ export declare const extractTraceContext: (...args: any[]) => never;
17
+ export declare const injectTraceContext: (...args: any[]) => never;
18
+ export declare const withExtractedContext: (...args: any[]) => never;
19
+ export declare const getCurrentTelemetryInfo: () => {
20
+ traceId: undefined;
21
+ spanId: undefined;
22
+ isRecording: boolean;
23
+ };
24
+ export type TelemetryConfig = any;
25
+ export type LogContext = Record<string, any>;
26
+ export type LogEntry = any;
27
+ export type ArcTelemetryContext = any;
28
+ export declare const SpanKind: {
29
+ readonly INTERNAL: "internal";
30
+ readonly SERVER: "server";
31
+ readonly CLIENT: "client";
32
+ readonly PRODUCER: "producer";
33
+ readonly CONSUMER: "consumer";
34
+ };
35
+ export declare const SpanStatusCode: {
36
+ readonly UNSET: 0;
37
+ readonly OK: 1;
38
+ readonly ERROR: 2;
39
+ };
40
+ export declare const LogLevel: {
41
+ readonly ERROR: "error";
42
+ readonly WARN: "warn";
43
+ readonly INFO: "info";
44
+ readonly DEBUG: "debug";
45
+ readonly TRACE: "trace";
46
+ };
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,84 @@
1
+ import type { AuthContext } from '../context/element';
2
+ /**
3
+ * Environment-agnostic telemetry context that handlers receive
4
+ * Automatically correlates logs with trace IDs
5
+ */
6
+ export interface TelemetryContext {
7
+ /**
8
+ * Logging methods that auto-correlate with trace ID
9
+ */
10
+ log: {
11
+ info(message: string, context?: Record<string, any>): void;
12
+ error(message: string, context?: Record<string, any>, error?: Error): void;
13
+ debug(message: string, context?: Record<string, any>): void;
14
+ warn(message: string, context?: Record<string, any>): void;
15
+ command(name: string, message: string, context?: Record<string, any>): void;
16
+ event(type: string, message: string, context?: Record<string, any>): void;
17
+ database(operation: string, message: string, context?: Record<string, any>): void;
18
+ http(method: string, path: string, statusCode: number, duration: number, context?: Record<string, any>): void;
19
+ };
20
+ /**
21
+ * Span management (automatically correlates logs with traces)
22
+ */
23
+ startSpan(name: string, attributes?: Record<string, string | number | boolean>): void;
24
+ addAttributes(attributes: Record<string, string | number | boolean>): void;
25
+ addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
26
+ recordException(error: Error | string): void;
27
+ /**
28
+ * Trace correlation info
29
+ */
30
+ getTraceId(): string | undefined;
31
+ getSpanId(): string | undefined;
32
+ }
33
+ /**
34
+ * Span options for creating new spans
35
+ */
36
+ export interface SpanOptions {
37
+ kind?: 'client' | 'server' | 'internal' | 'producer' | 'consumer';
38
+ attributes?: Record<string, string | number | boolean>;
39
+ }
40
+ /**
41
+ * Main telemetry provider interface that environments must implement
42
+ */
43
+ export interface TelemetryProvider {
44
+ /**
45
+ * Create a logger instance
46
+ */
47
+ createLogger(name: string): Logger;
48
+ /**
49
+ * Execute function within a span context
50
+ */
51
+ withSpan<T>(name: string, fn: (context: TelemetryContext) => Promise<T> | T, options?: SpanOptions): Promise<T>;
52
+ /**
53
+ * Create telemetry context for command/route handlers
54
+ */
55
+ createTelemetryContext(authContext: AuthContext, operationType: 'command' | 'event' | 'listener' | 'view' | 'route', operationName: string): TelemetryContext;
56
+ /**
57
+ * Check if telemetry is enabled
58
+ */
59
+ isEnabled(): boolean;
60
+ }
61
+ /**
62
+ * Basic logger interface
63
+ */
64
+ export interface Logger {
65
+ info(message: string, context?: Record<string, any>): void;
66
+ error(message: string, context?: Record<string, any>, error?: Error): void;
67
+ debug(message: string, context?: Record<string, any>): void;
68
+ warn(message: string, context?: Record<string, any>): void;
69
+ command(name: string, message: string, context?: Record<string, any>): void;
70
+ event(type: string, message: string, context?: Record<string, any>): void;
71
+ database(operation: string, message: string, context?: Record<string, any>): void;
72
+ http(method: string, path: string, statusCode: number, duration: number, context?: Record<string, any>): void;
73
+ child(context: Record<string, any>): Logger;
74
+ }
75
+ /**
76
+ * Database telemetry interface for adapters
77
+ */
78
+ export interface DatabaseTelemetry {
79
+ /**
80
+ * Execute a database operation with telemetry
81
+ */
82
+ withDatabaseOperation<T>(operation: string, sql: string, params: any[] | undefined, tableName: string | undefined, fn: () => Promise<T>): Promise<T>;
83
+ }
84
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1,67 @@
1
+ export declare enum LogLevel {
2
+ ERROR = "error",
3
+ WARN = "warn",
4
+ INFO = "info",
5
+ DEBUG = "debug",
6
+ TRACE = "trace"
7
+ }
8
+ interface LogContext {
9
+ [key: string]: any;
10
+ }
11
+ interface LogEntry {
12
+ level: LogLevel;
13
+ message: string;
14
+ context?: LogContext;
15
+ timestamp?: string;
16
+ traceId?: string;
17
+ spanId?: string;
18
+ userId?: string;
19
+ requestId?: string;
20
+ command?: string;
21
+ event?: string;
22
+ error?: Error;
23
+ }
24
+ declare class ArcLogger {
25
+ private serviceName;
26
+ constructor(serviceName?: string);
27
+ private createLogEntry;
28
+ private formatForConsole;
29
+ private output;
30
+ private getSeverityNumber;
31
+ error(message: string, context?: LogContext, error?: Error): void;
32
+ warn(message: string, context?: LogContext): void;
33
+ info(message: string, context?: LogContext): void;
34
+ debug(message: string, context?: LogContext): void;
35
+ trace(message: string, context?: LogContext): void;
36
+ /**
37
+ * Log command execution
38
+ */
39
+ command(commandName: string, message: string, context?: LogContext): void;
40
+ /**
41
+ * Log event processing
42
+ */
43
+ event(eventType: string, message: string, context?: LogContext): void;
44
+ /**
45
+ * Log database operations
46
+ */
47
+ database(operation: string, message: string, context?: LogContext): void;
48
+ /**
49
+ * Log HTTP requests
50
+ */
51
+ http(method: string, path: string, statusCode: number, duration: number, context?: LogContext): void;
52
+ /**
53
+ * Create a child logger with additional context
54
+ */
55
+ child(context: LogContext): ArcLogger;
56
+ }
57
+ /**
58
+ * Initialize global logger
59
+ */
60
+ export declare function initializeLogger(serviceName?: string): ArcLogger;
61
+ /**
62
+ * Get the global logger instance
63
+ */
64
+ export declare function getLogger(): ArcLogger;
65
+ export { ArcLogger };
66
+ export type { LogContext, LogEntry };
67
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,54 @@
1
+ import type { TelemetryProvider, TelemetryContext, Logger, DatabaseTelemetry } from './interfaces';
2
+ /**
3
+ * No-op logger implementation for when telemetry is disabled
4
+ */
5
+ export declare class NoOpLogger implements Logger {
6
+ info(): void;
7
+ error(): void;
8
+ debug(): void;
9
+ warn(): void;
10
+ command(): void;
11
+ event(): void;
12
+ database(): void;
13
+ http(): void;
14
+ child(): Logger;
15
+ }
16
+ /**
17
+ * No-op telemetry context for when telemetry is disabled
18
+ */
19
+ export declare class NoOpTelemetryContext implements TelemetryContext {
20
+ private logger;
21
+ log: NoOpLogger;
22
+ startSpan(): void;
23
+ addAttributes(): void;
24
+ addEvent(): void;
25
+ recordException(): void;
26
+ getTraceId(): undefined;
27
+ getSpanId(): undefined;
28
+ }
29
+ /**
30
+ * No-op telemetry provider for when telemetry is disabled
31
+ */
32
+ export declare class NoOpTelemetryProvider implements TelemetryProvider {
33
+ private logger;
34
+ private context;
35
+ createLogger(): Logger;
36
+ withSpan<T>(name: string, fn: (context: TelemetryContext) => Promise<T> | T): Promise<T>;
37
+ createTelemetryContext(): TelemetryContext;
38
+ isEnabled(): boolean;
39
+ }
40
+ /**
41
+ * No-op database telemetry for when telemetry is disabled
42
+ */
43
+ export declare class NoOpDatabaseTelemetry implements DatabaseTelemetry {
44
+ withDatabaseOperation<T>(operation: string, sql: string, params: any[] | undefined, tableName: string | undefined, fn: () => Promise<T>): Promise<T>;
45
+ }
46
+ /**
47
+ * Default no-op telemetry provider instance
48
+ */
49
+ export declare const noOpTelemetryProvider: NoOpTelemetryProvider;
50
+ /**
51
+ * Default no-op database telemetry instance
52
+ */
53
+ export declare const noOpDatabaseTelemetry: NoOpDatabaseTelemetry;
54
+ //# sourceMappingURL=no-op.d.ts.map
@@ -0,0 +1,85 @@
1
+ import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
2
+ import type { Span } from "@opentelemetry/api";
3
+ interface TelemetryConfig {
4
+ serviceName: string;
5
+ serviceVersion: string;
6
+ environment: string;
7
+ otlpEndpoint?: string;
8
+ enabled?: boolean;
9
+ }
10
+ declare class ArcTelemetry {
11
+ private sdk?;
12
+ private tracer;
13
+ private logger;
14
+ private config;
15
+ constructor(config: TelemetryConfig);
16
+ private initialize;
17
+ /**
18
+ * Create a new span for tracing operations
19
+ */
20
+ startSpan(name: string, options?: {
21
+ kind?: SpanKind;
22
+ attributes?: Record<string, string | number | boolean>;
23
+ parent?: Span;
24
+ }): Span;
25
+ /**
26
+ * Execute a function within a span context
27
+ */
28
+ withSpan<T>(name: string, fn: (span: Span) => Promise<T> | T, options?: {
29
+ kind?: SpanKind;
30
+ attributes?: Record<string, string | number | boolean>;
31
+ }): Promise<T>;
32
+ /**
33
+ * Add attributes to the current active span
34
+ */
35
+ addSpanAttributes(attributes: Record<string, string | number | boolean>): void;
36
+ /**
37
+ * Add an event to the current active span
38
+ */
39
+ addSpanEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
40
+ /**
41
+ * Record an exception in the current span
42
+ */
43
+ recordException(error: Error | string): void;
44
+ /**
45
+ * Shutdown telemetry (call on app shutdown)
46
+ */
47
+ shutdown(): Promise<void>;
48
+ /**
49
+ * Check if telemetry is enabled
50
+ */
51
+ get isEnabled(): boolean;
52
+ /**
53
+ * Get the current tracer instance
54
+ */
55
+ getTracer(): any;
56
+ /**
57
+ * Get the current logger instance
58
+ */
59
+ getLogger(): any;
60
+ }
61
+ /**
62
+ * Initialize global telemetry
63
+ */
64
+ export declare function initializeTelemetry(config: TelemetryConfig): ArcTelemetry;
65
+ /**
66
+ * Get the global telemetry instance
67
+ */
68
+ export declare function getTelemetry(): ArcTelemetry | null;
69
+ /**
70
+ * Helper function to create a span
71
+ */
72
+ export declare function startSpan(name: string, options?: {
73
+ kind?: SpanKind;
74
+ attributes?: Record<string, string | number | boolean>;
75
+ }): Span;
76
+ /**
77
+ * Helper function to execute code within a span
78
+ */
79
+ export declare function withSpan<T>(name: string, fn: (span: Span) => Promise<T> | T, options?: {
80
+ kind?: SpanKind;
81
+ attributes?: Record<string, string | number | boolean>;
82
+ }): Promise<T>;
83
+ export { ArcTelemetry, SpanKind, SpanStatusCode };
84
+ export type { TelemetryConfig };
85
+ //# sourceMappingURL=tracer.d.ts.map
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- import type { ArcCollectionAny, CollectionItem } from "./collection/collection";
2
- import type { QueryCollectionResult } from "./collection/queries/find";
3
1
  import type { ArcElement } from "./elements/element";
4
- export * from "./utils/index";
5
2
  export declare namespace objectUtil {
6
3
  export type MergeShapes<U, V> = {
7
4
  [k in Exclude<keyof U, keyof V>]: U[k];
@@ -43,23 +40,7 @@ export declare namespace objectUtil {
43
40
  export declare namespace util {
44
41
  type FirstArgument<T> = T extends (arg: infer U, ...args: any[]) => any ? U : never;
45
42
  type GetType<Element extends ArcElement> = ReturnType<Element["deserialize"]>;
46
- type CollectionItemWithId<C extends ArcCollectionAny> = ReturnType<C["deserialize"]>;
47
43
  }
48
- export type ContextTypes<Ctx extends {
49
- elements: any[];
50
- }> = {
51
- [key in keyof Ctx["elements"]]: Ctx["elements"][key] extends ArcCollectionAny ? {
52
- [Collection in Ctx["elements"][number] as `${Collection["name"]}.bodyWithoutId`]: util.GetType<Collection["schema"]>;
53
- } & {
54
- [Collection in Ctx["elements"][number] as `${Collection["name"]}.setBody`]: objectUtil.addQuestionMarks<util.FirstArgument<Collection["schema"]["parse"]>>;
55
- } & {
56
- [Collection in Ctx["elements"][number] as `${Collection["name"]}.id`]: util.GetType<Collection["id"]>;
57
- } & {
58
- [Collection in Ctx["elements"][number] as `${Collection["name"]}.body`]: CollectionItem<Collection>;
59
- } & {
60
- [Collection in Ctx["elements"][number] as `${Collection["name"]}.queryCollectionResult`]: Omit<QueryCollectionResult<Collection>, "result">;
61
- } : never;
62
- }[keyof Ctx["elements"]];
63
44
  export type DeepPartial<T> = {
64
45
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
65
46
  };
@@ -1,5 +1,5 @@
1
- import type { ArcEventAny, ArcEventInstance } from "../context";
2
- import { ArcContextElementWithStore, type ArcContextElementAny, type AuthContext, type ListenerConfig, type PublishEventFunction, type StoreSchema } from "../context/element";
1
+ import { type ArcEventAny, type ArcEventInstance } from "../context";
2
+ import { ArcContextElementWithStore, type ArcContextElementAny, type AuthContext, type DatabaseStoreSchema, type ListenerConfig, type PublishEventFunction } from "../context/element";
3
3
  import type { QueryBuilderContext } from "../context/query-builder-context";
4
4
  import type { DataStorage } from "../data-storage";
5
5
  import type { FindOptions, WhereCondition } from "../data-storage/types";
@@ -31,9 +31,10 @@ export declare class ArcView<Name extends string, Id extends ArcIdAny, Schema ex
31
31
  private _elements?;
32
32
  private _handler?;
33
33
  private _isAsync;
34
+ private _version?;
34
35
  private restrictions?;
35
36
  constructor(name: Name, id: Id, schema: Schema);
36
- storeSchema: () => StoreSchema;
37
+ databaseStoreSchema: () => DatabaseStoreSchema;
37
38
  /**
38
39
  * Define read access restrictions for this view
39
40
  * @param restrictionsFn - Function that takes auth context and returns where condition for read access
@@ -42,6 +43,7 @@ export declare class ArcView<Name extends string, Id extends ArcIdAny, Schema ex
42
43
  use<const E extends ArcContextElementAny[]>(elements: E): ArcView<Name, Id, Schema, E>;
43
44
  description(description: string): ArcView<Name, Id, Schema, Elements>;
44
45
  async(): ArcView<Name, Id, Schema, Elements>;
46
+ version(version: number): ArcView<Name, Id, Schema, Elements>;
45
47
  handle<Handler extends ArcViewHandler<Elements, Id, Schema>>(handler: Handler): ArcView<Name, Id, Schema, Elements>;
46
48
  handleEvent<Event extends ArcEventAny>(event: Event, handler: ArcViewEventHandler<Id, Schema, ArcEventInstance<Event>>): ArcView<Name, Id, Schema, [...Elements, Event]>;
47
49
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc",
3
3
  "type": "module",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "Arc is a framework designed to align code closely with business logic, streamlining development and enhancing productivity.",
@@ -1,81 +0,0 @@
1
- import { ArcContextElementWithStore, type AuthContext, type AuthorizationRestrictions, type StoreSchema } from "../context/element";
2
- import { type ArcIdAny } from "../elements/id";
3
- import { type ArcObjectAny } from "../elements/object";
4
- import { type $type, type DeepPartial, type objectUtil, type util } from "../utils";
5
- import type { QueryBuilderContext } from "../context/query-builder-context";
6
- import type { DataStorage } from "../data-storage";
7
- import type { FindOptions } from "../data-storage/types";
8
- import { ArcFindQueryBuilder } from "./query-builders/find";
9
- export type CollectionItem<C extends ArcCollectionAny> = objectUtil.simplify<{
10
- _id: string;
11
- } & $type<C>>;
12
- export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny> = objectUtil.simplify<{
13
- _id: $type<Id>;
14
- } & $type<Schema>>;
15
- export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> extends ArcContextElementWithStore<{
16
- type: "delete";
17
- from: CollectionItem<ArcCollection<Name, Id, Schema>>;
18
- } | {
19
- type: "set";
20
- to: CollectionItem<ArcCollection<Name, Id, Schema>>;
21
- } | {
22
- type: "modify";
23
- from: CollectionItem<ArcCollection<Name, Id, Schema>>;
24
- to: CollectionItem<ArcCollection<Name, Id, Schema>>;
25
- changes: objectUtil.simplify<DeepPartial<util.FirstArgument<Schema["serialize"]>>>;
26
- } | {
27
- type: "mutate";
28
- from: CollectionItem<ArcCollection<Name, Id, Schema>>;
29
- to: CollectionItem<ArcCollection<Name, Id, Schema>>;
30
- }, Name> {
31
- readonly name: Name;
32
- readonly id: Id;
33
- readonly schema: Schema;
34
- readonly options: ArcCollectionOptions<Id, Schema>;
35
- private _restrictions?;
36
- constructor(name: Name, id: Id, schema: Schema, options: ArcCollectionOptions<Id, Schema>);
37
- storeSchema(): StoreSchema;
38
- /**
39
- * Default restrictions for collections - deny all by default
40
- * Use the auth() method to define custom authorization logic
41
- */
42
- restrictions(authContext: AuthContext): AuthorizationRestrictions;
43
- /**
44
- * Define custom authorization restrictions for this collection
45
- * @param restrictionsFn - Function that takes auth context and returns restrictions
46
- */
47
- auth(restrictionsFn: (authContext: AuthContext) => AuthorizationRestrictions): ArcCollection<Name, Id, Schema>;
48
- serialize(data: objectUtil.simplify<{
49
- _id: util.FirstArgument<Id["serialize"]>;
50
- } & objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>>): objectUtil.simplify<{
51
- _id: ReturnType<Id["serialize"]>;
52
- } & ReturnType<Schema["serialize"]>>;
53
- deserialize(data: objectUtil.simplify<{
54
- _id: util.FirstArgument<Id["deserialize"]>;
55
- } & objectUtil.addQuestionMarks<util.FirstArgument<Schema["deserialize"]>>>): Deserialize<Id, Schema>;
56
- queryBuilder: (context: QueryBuilderContext) => {
57
- find: (options?: FindOptions<CollectionItem<ArcCollection<Name, Id, Schema>>>) => ArcFindQueryBuilder<ArcCollection<Name, Id, Schema>>;
58
- };
59
- commandContext: (dataStorage: DataStorage, publishEvent: (event: this["$event"]) => Promise<void>) => {
60
- add: (data: $type<Schema>) => Promise<{
61
- id: any;
62
- }>;
63
- remove: (id: $type<Id>) => Promise<{
64
- success: boolean;
65
- }>;
66
- set: (id: $type<Id>, data: $type<Schema>) => Promise<{
67
- success: boolean;
68
- }>;
69
- find: (options: FindOptions<Deserialize<Id, Schema>>) => Promise<Deserialize<Id, Schema>[]>;
70
- findOne: (where: FindOptions<Deserialize<Id, Schema>>["where"]) => Promise<Deserialize<Id, Schema> | undefined>;
71
- modify: (id: $type<Id>, data: DeepPartial<$type<Schema>>) => Promise<void>;
72
- edit: (id: $type<Id>, editCallback: (item: Deserialize<Id, Schema>) => void) => Promise<void>;
73
- };
74
- }
75
- export type ArcCollectionAny = ArcCollection<any, any, any>;
76
- type ArcCollectionOptions<Id extends ArcIdAny, Schema extends ArcObjectAny> = {
77
- sort?: (a: Deserialize<Id, Schema>, b: Deserialize<Id, Schema>) => number;
78
- };
79
- export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny>(name: Name, id: Id, schema: Schema, options?: ArcCollectionOptions<Id, Schema>): ArcCollection<Name, Id, Schema>;
80
- export {};
81
- //# sourceMappingURL=collection.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from "./collection";
2
- export * from "./queries/abstract-collection-query";
3
- export * from "./queries/util";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,14 +0,0 @@
1
- import { ArcSerializableQuery } from "../../context/serializable-query";
2
- import type { DataStorage, ListenerEvent, StoreState } from "../../data-storage";
3
- import type { ArcCollectionAny, CollectionItem } from "../collection";
4
- export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Result, Params> extends ArcSerializableQuery<Result, Params> {
5
- protected collection: Collection;
6
- protected bindedChangeHandler: (changes: ListenerEvent<CollectionItem<Collection>>[]) => void;
7
- private store;
8
- constructor(collection: Collection, params: Params);
9
- run(dataStorage: DataStorage): Promise<Result>;
10
- protected abstract onChange(change: ListenerEvent<CollectionItem<Collection>>): Result | false;
11
- protected abstract fetch(store: StoreState<CollectionItem<Collection>>): Promise<Result>;
12
- protected changeHandler(changes: ListenerEvent<CollectionItem<Collection>>[]): void;
13
- }
14
- //# sourceMappingURL=abstract-collection-query.d.ts.map
@@ -1,29 +0,0 @@
1
- import type { ListenerEvent, StoreState } from "../../data-storage";
2
- import type { FindOptions } from "../../data-storage/types";
3
- import type { util } from "../../utils";
4
- import type { ArcCollectionAny, CollectionItem } from "../collection";
5
- import { ArcCollectionQuery } from "./abstract-collection-query";
6
- export declare class QueryCollectionResult<C extends ArcCollectionAny> {
7
- private result;
8
- constructor(result: CollectionItem<C>[]);
9
- get(id: util.GetType<C["id"]> | null): ({
10
- _id: string;
11
- } & ReturnType<C["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
12
- _id: string;
13
- } & ReturnType<C["deserialize"]>)[KeyType]; } : never) | undefined;
14
- map<U>(callbackfn: (value: CollectionItem<C>, index: number, array: CollectionItem<C>[]) => U): U[];
15
- toArray(): ({
16
- _id: string;
17
- } & ReturnType<C["deserialize"]> extends infer T ? { [KeyType in keyof T]: ({
18
- _id: string;
19
- } & ReturnType<C["deserialize"]>)[KeyType]; } : never)[];
20
- }
21
- export declare class ArcFindQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, QueryCollectionResult<Collection>, FindOptions<CollectionItem<Collection>>> {
22
- protected params: FindOptions<CollectionItem<Collection>>;
23
- constructor(collection: Collection, params: FindOptions<CollectionItem<Collection>>);
24
- protected fetch(store: StoreState<CollectionItem<Collection>>): Promise<QueryCollectionResult<Collection>>;
25
- protected checkItem(item: CollectionItem<Collection>): boolean;
26
- protected onChange(change: ListenerEvent<CollectionItem<Collection>>): false | QueryCollectionResult<Collection>;
27
- protected createResult(result: CollectionItem<Collection>[]): QueryCollectionResult<Collection>;
28
- }
29
- //# sourceMappingURL=find.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=one-item.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { ArcContextAny, QueryFactoryFunction } from "../../context";
2
- export type QueryBuilderFunctionResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]>["lastResult"];
3
- //# sourceMappingURL=util.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=find-by-id.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=find-one.d.ts.map
@@ -1,13 +0,0 @@
1
- import { QueryBuilderContext } from "../../context/query-builder-context";
2
- import type { FindOptions } from "../../data-storage/types";
3
- import { type ArcCollectionAny, type CollectionItem } from "../collection";
4
- import { ArcFindQuery } from "../queries/find";
5
- export declare class ArcFindQueryBuilder<C extends ArcCollectionAny> {
6
- private collection;
7
- protected queryContext: QueryBuilderContext;
8
- protected options: FindOptions<CollectionItem<C>>;
9
- constructor(collection: C, queryContext: QueryBuilderContext, options: FindOptions<CollectionItem<C>>);
10
- toQuery(): ArcFindQuery<ArcCollectionAny>;
11
- run(): import("../queries/find").QueryCollectionResult<ArcCollectionAny>;
12
- }
13
- //# sourceMappingURL=find.d.ts.map