@casual-simulation/aux-records 3.4.6-alpha.14601027727 → 3.5.0-alpha.15117651144
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.
- package/AIController.js +835 -890
- package/AIController.js.map +1 -1
- package/AIHumeInterface.js +43 -54
- package/AIHumeInterface.js.map +1 -1
- package/AIOpenAIRealtimeInterface.js +60 -71
- package/AIOpenAIRealtimeInterface.js.map +1 -1
- package/AnthropicAIChatInterface.js +96 -142
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +3 -2
- package/AuthController.js +1907 -1933
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -10
- package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.js +30 -45
- package/CachingConfigStore.js.map +1 -1
- package/CachingPolicyStore.d.ts +8 -2
- package/CachingPolicyStore.js +108 -135
- package/CachingPolicyStore.js.map +1 -1
- package/ComIdConfig.d.ts +18 -18
- package/ComIdConfig.js.map +1 -1
- package/ConsoleAuthMessenger.js +7 -20
- package/ConsoleAuthMessenger.js.map +1 -1
- package/DataRecordsController.d.ts +2 -2
- package/DataRecordsController.js +369 -377
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/DataRecordsStore.js +1 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.js +226 -240
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -2
- package/FileRecordsController.js +458 -450
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +133 -179
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +43 -54
- package/LivekitController.js.map +1 -1
- package/LoomController.js +64 -75
- package/LoomController.js.map +1 -1
- package/MemoryAuthMessenger.js +10 -23
- package/MemoryAuthMessenger.js.map +1 -1
- package/MemoryCache.js +18 -35
- package/MemoryCache.js.map +1 -1
- package/MemoryFileRecordsLookup.js +105 -125
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryModerationJobProvider.js +17 -30
- package/MemoryModerationJobProvider.js.map +1 -1
- package/MemoryRateLimiter.js +12 -27
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +18 -6
- package/MemoryStore.js +1879 -1997
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +2 -2
- package/ModerationController.js +186 -200
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +105 -135
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +57 -51
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +150 -10
- package/PolicyController.js +1546 -1299
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +110 -2
- package/PolicyStore.js +36 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.js +398 -435
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +25 -36
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.js +51 -74
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +2 -42
- package/RecordsController.js +1026 -1182
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +196 -27
- package/RecordsServer.js +1701 -1343
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +1 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +339 -195
- package/ServerConfig.js +13 -0
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +62 -75
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +150 -167
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +6 -1
- package/SubscriptionConfigBuilder.js +22 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +266 -169
- package/SubscriptionConfiguration.js +101 -79
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +2 -1
- package/SubscriptionController.js +643 -650
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +21 -4
- package/SystemNotificationMessenger.js +36 -30
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +9 -1
- package/TestUtils.js +105 -129
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +2 -16
- package/Utils.js +21 -22
- package/Utils.js.map +1 -1
- package/crud/CrudHelpers.js +17 -26
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +1 -1
- package/crud/CrudRecordsController.js +259 -267
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.js +174 -185
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/CrudRecordsStore.d.ts +7 -3
- package/crud/MemoryCrudRecordsStore.d.ts +4 -4
- package/crud/MemoryCrudRecordsStore.js +98 -118
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
- package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
- package/crud/sub/SubCrudRecordsController.d.ts +182 -0
- package/crud/sub/SubCrudRecordsController.js +360 -0
- package/crud/sub/SubCrudRecordsController.js.map +1 -0
- package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
- package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
- package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
- package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
- package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
- package/crud/sub/SubCrudRecordsStore.js.map +1 -0
- package/crud/sub/index.d.ts +3 -0
- package/crud/sub/index.js +20 -0
- package/{forms → crud/sub}/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/notifications/MemoryNotificationRecordsStore.js +189 -198
- package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
- package/notifications/NotificationRecordsController.js +438 -460
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/NotificationRecordsStore.d.ts +2 -1
- package/notifications/WebPushInterface.d.ts +0 -1
- package/notifications/WebPushInterface.js +0 -1
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +6 -6
- package/packages/MemoryPackageRecordsStore.d.ts +10 -0
- package/packages/MemoryPackageRecordsStore.js +38 -0
- package/packages/MemoryPackageRecordsStore.js.map +1 -0
- package/packages/PackageRecordsController.d.ts +26 -0
- package/packages/PackageRecordsController.js +49 -0
- package/packages/PackageRecordsController.js.map +1 -0
- package/packages/PackageRecordsStore.d.ts +32 -0
- package/packages/PackageRecordsStore.js +19 -0
- package/packages/PackageRecordsStore.js.map +1 -0
- package/packages/index.d.ts +4 -0
- package/packages/index.js +21 -0
- package/packages/index.js.map +1 -0
- package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
- package/packages/version/PackageVersionRecordsController.d.ts +144 -0
- package/packages/version/PackageVersionRecordsController.js +656 -0
- package/packages/version/PackageVersionRecordsController.js.map +1 -0
- package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
- package/packages/version/PackageVersionRecordsStore.js +126 -0
- package/packages/version/PackageVersionRecordsStore.js.map +1 -0
- package/packages/version/index.d.ts +4 -0
- package/packages/version/index.js +21 -0
- package/packages/version/index.js.map +1 -0
- package/tracing/TracingDecorators.js +31 -40
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/MemoryWebhookRecordsStore.js +56 -72
- package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +3 -3
- package/webhooks/WebhookRecordsController.d.ts +2 -1
- package/webhooks/WebhookRecordsController.js +389 -382
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/webhooks/WebhookRecordsStore.d.ts +2 -1
- package/websockets/InstRecordsStore.d.ts +50 -0
- package/websockets/InstRecordsStore.js +17 -0
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
- package/websockets/MemoryTempInstRecordsStore.js +168 -179
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +98 -135
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +29 -48
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.d.ts +4 -1
- package/websockets/SplitInstRecordsStore.js +167 -185
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
- package/websockets/TemporaryInstRecordsStore.js +17 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +147 -3
- package/websockets/WebsocketController.js +1735 -1391
- package/websockets/WebsocketController.js.map +1 -1
- package/websockets/index.d.ts +0 -1
- package/websockets/index.js +0 -1
- package/websockets/index.js.map +1 -1
- package/AAGUID.d.ts +0 -11
- package/AAGUID.js +0 -116
- package/AAGUID.js.map +0 -1
- package/AuthUtils.d.ts +0 -162
- package/AuthUtils.js +0 -327
- package/AuthUtils.js.map +0 -1
- package/forms/FormError.d.ts +0 -43
- package/forms/FormError.js +0 -56
- package/forms/FormError.js.map +0 -1
- package/forms/index.d.ts +0 -2
- package/websockets/Utils.d.ts +0 -33
- package/websockets/Utils.js +0 -82
- package/websockets/Utils.js.map +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { AuthorizationContext, AuthorizeUserAndInstancesForResourcesSuccess, AuthorizeUserAndInstancesSuccess, PolicyController } from '../../PolicyController';
|
|
2
|
+
import type { ConfigurationStore } from '../../ConfigurationStore';
|
|
3
|
+
import type { ActionKinds, ResourceKinds } from '@casual-simulation/aux-common';
|
|
4
|
+
import type { SubCrudRecord, SubCrudRecordsStore } from './SubCrudRecordsStore';
|
|
5
|
+
import type { CrudRecord, CrudRecordsStore } from '../CrudRecordsStore';
|
|
6
|
+
import type { CheckSubscriptionMetricsResult, CrudEraseItemResult, CrudGetItemResult, CrudListItemsResult, CrudRecordItemRequest, CrudRecordItemResult } from '../CrudRecordsController';
|
|
7
|
+
export interface SubCrudRecordsConfiguration<TKey, T extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, T> = SubCrudRecordsStore<TKey, T>, TRecordStore extends CrudRecordsStore<CrudRecord> = CrudRecordsStore<CrudRecord>> {
|
|
8
|
+
/**
|
|
9
|
+
* The name for the controller.
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* The store that the controller uses.
|
|
14
|
+
*/
|
|
15
|
+
store: TStore;
|
|
16
|
+
/**
|
|
17
|
+
* The record item store that the controller uses.
|
|
18
|
+
*/
|
|
19
|
+
recordItemStore: TRecordStore;
|
|
20
|
+
/**
|
|
21
|
+
* The policy controller.
|
|
22
|
+
*/
|
|
23
|
+
policies: PolicyController;
|
|
24
|
+
/**
|
|
25
|
+
* The configuration store.
|
|
26
|
+
*/
|
|
27
|
+
config: ConfigurationStore;
|
|
28
|
+
/**
|
|
29
|
+
* The kind of resource that the controller is for.
|
|
30
|
+
*/
|
|
31
|
+
resourceKind: ResourceKinds;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Defines a controller that can be used to present a CRUD API for a record.
|
|
35
|
+
*
|
|
36
|
+
* This controller is designed to be a base class that can be extended to make basic Create, Read, Update, and Delete operations on items in a record.
|
|
37
|
+
*
|
|
38
|
+
* @param TKey The type of the key for each item stored by this controller.
|
|
39
|
+
* @param T The type of the records that the controller can manage.
|
|
40
|
+
* @param TMetrics The type of the metrics that the controller can provide.
|
|
41
|
+
* @param TStore The type of the store that the controller uses.
|
|
42
|
+
* @param TRecordStore The type of the store that the controller uses for record items.
|
|
43
|
+
* @param TResult The type of the result that the controller returns to clients. Must be a subset of T.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class SubCrudRecordsController<TKey, T extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, T> = SubCrudRecordsStore<TKey, T>, TRecordStore extends CrudRecordsStore<CrudRecord> = CrudRecordsStore<CrudRecord>, TResult extends Partial<T> = T> {
|
|
46
|
+
private _store;
|
|
47
|
+
private _recordStore;
|
|
48
|
+
private _policies;
|
|
49
|
+
private _config;
|
|
50
|
+
private _name;
|
|
51
|
+
private _resourceKind;
|
|
52
|
+
protected get config(): ConfigurationStore;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the name of the controller.
|
|
55
|
+
*/
|
|
56
|
+
get name(): string;
|
|
57
|
+
protected get policies(): PolicyController;
|
|
58
|
+
protected get store(): TStore;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the kind of resources that this controller is for.
|
|
61
|
+
*/
|
|
62
|
+
get resourceKind(): ResourceKinds;
|
|
63
|
+
constructor(config: SubCrudRecordsConfiguration<TKey, T, TStore, TRecordStore>);
|
|
64
|
+
/**
|
|
65
|
+
* Creates or updates an item in the given record.
|
|
66
|
+
* @param request The request.
|
|
67
|
+
*/
|
|
68
|
+
recordItem(request: CrudRecordItemRequest<T>): Promise<CrudRecordItemResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Updates or creates the item in the given record.
|
|
71
|
+
* @param action The action that is being performed.
|
|
72
|
+
* @param recordName The name of the record.
|
|
73
|
+
* @param item The item that should be updated or created.
|
|
74
|
+
* @param context The authorization context.
|
|
75
|
+
* @param authorization The authorization for the user and instances.
|
|
76
|
+
* @param request The request.
|
|
77
|
+
*/
|
|
78
|
+
protected _putItem(action: 'update' | 'create', recordName: string, item: T, context: AuthorizationContext, authorization: AuthorizeUserAndInstancesForResourcesSuccess, request: CrudRecordItemRequest<T>): Promise<CrudRecordItemResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the item with the given address from the given record.
|
|
81
|
+
* @param request The request to get the item.
|
|
82
|
+
*/
|
|
83
|
+
getItem(request: SubCrudGetItemRequest<TKey>): Promise<CrudGetItemResult<TResult>>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes the item with the given address from the given record.
|
|
86
|
+
* @param request The request.
|
|
87
|
+
*/
|
|
88
|
+
eraseItem(request: SubCrudEraseItemRequest<TKey>): Promise<CrudEraseItemResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Lists items in the given record.
|
|
91
|
+
* @param request The request.
|
|
92
|
+
*/
|
|
93
|
+
listItems(request: SubCrudListItemsRequest): Promise<CrudListItemsResult<TResult>>;
|
|
94
|
+
/**
|
|
95
|
+
* Checks that the given metrics are valid for the subscription.
|
|
96
|
+
* @param metrics The metrics that were fetched from the database.
|
|
97
|
+
* @param action The action that is being performed.
|
|
98
|
+
* @param authorization The authorization for the user and instances.
|
|
99
|
+
* @param item The item that should be checked. Omitted for delete actions.
|
|
100
|
+
*/
|
|
101
|
+
protected abstract _checkSubscriptionMetrics(action: ActionKinds, context: AuthorizationContext, authorization: AuthorizeUserAndInstancesSuccess | AuthorizeUserAndInstancesForResourcesSuccess, item?: T): Promise<CheckSubscriptionMetricsResult>;
|
|
102
|
+
/**
|
|
103
|
+
* Converts the given item to a version that is able to be returned to clients.
|
|
104
|
+
* Can be overriden to ensure that some fields are not returned.
|
|
105
|
+
* @param item The item that should be converted.
|
|
106
|
+
* @param context The authorization context.
|
|
107
|
+
* @returns The converted item.
|
|
108
|
+
*/
|
|
109
|
+
protected _convertItemToResult(item: T, context: AuthorizationContext): TResult;
|
|
110
|
+
/**
|
|
111
|
+
* Transforms the given input item and returns the transformed item.
|
|
112
|
+
* Useful for transforming items before they are stored.
|
|
113
|
+
* @param item The item that should be transformed.
|
|
114
|
+
*/
|
|
115
|
+
protected _transformInputItem(item: T): T;
|
|
116
|
+
}
|
|
117
|
+
export interface SubCrudGetItemRequest<TKey> {
|
|
118
|
+
/**
|
|
119
|
+
* The name of the record that the request is for.
|
|
120
|
+
* Can also be a record key.
|
|
121
|
+
*/
|
|
122
|
+
recordName: string;
|
|
123
|
+
/**
|
|
124
|
+
* The address of the record item that the item is stored in.
|
|
125
|
+
*/
|
|
126
|
+
address: string;
|
|
127
|
+
/**
|
|
128
|
+
* The key of the item to get.
|
|
129
|
+
*/
|
|
130
|
+
key: TKey;
|
|
131
|
+
/**
|
|
132
|
+
* The ID of the user who is currently logged in.
|
|
133
|
+
*/
|
|
134
|
+
userId: string;
|
|
135
|
+
/**
|
|
136
|
+
* The instances that the request is coming from.
|
|
137
|
+
*/
|
|
138
|
+
instances: string[];
|
|
139
|
+
}
|
|
140
|
+
export interface SubCrudEraseItemRequest<TKey> {
|
|
141
|
+
/**
|
|
142
|
+
* The name of the record that the request is for.
|
|
143
|
+
* Can also be a record key.
|
|
144
|
+
*/
|
|
145
|
+
recordName: string;
|
|
146
|
+
/**
|
|
147
|
+
* The address of the item that should be erased.
|
|
148
|
+
*/
|
|
149
|
+
address: string;
|
|
150
|
+
/**
|
|
151
|
+
* The key of the item that should be erased.
|
|
152
|
+
*/
|
|
153
|
+
key: TKey;
|
|
154
|
+
/**
|
|
155
|
+
* The ID of the user who is currently logged in.
|
|
156
|
+
*/
|
|
157
|
+
userId: string;
|
|
158
|
+
/**
|
|
159
|
+
* The instances that the request is coming from.
|
|
160
|
+
*/
|
|
161
|
+
instances: string[];
|
|
162
|
+
}
|
|
163
|
+
export interface SubCrudListItemsRequest {
|
|
164
|
+
/**
|
|
165
|
+
* The name of the record that the request is for.
|
|
166
|
+
* Can also be a record key.
|
|
167
|
+
*/
|
|
168
|
+
recordName: string;
|
|
169
|
+
/**
|
|
170
|
+
* The address that the items should be listed for.
|
|
171
|
+
*/
|
|
172
|
+
address: string;
|
|
173
|
+
/**
|
|
174
|
+
* The ID of the user who is currently logged in.
|
|
175
|
+
*/
|
|
176
|
+
userId: string;
|
|
177
|
+
/**
|
|
178
|
+
* The instances that the request is coming from.
|
|
179
|
+
*/
|
|
180
|
+
instances: string[];
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=SubCrudRecordsController.d.ts.map
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { traced } from '../../tracing/TracingDecorators';
|
|
8
|
+
import { SpanStatusCode, trace } from '@opentelemetry/api';
|
|
9
|
+
const TRACE_NAME = 'SubCrudRecordsController';
|
|
10
|
+
/**
|
|
11
|
+
* Defines a controller that can be used to present a CRUD API for a record.
|
|
12
|
+
*
|
|
13
|
+
* This controller is designed to be a base class that can be extended to make basic Create, Read, Update, and Delete operations on items in a record.
|
|
14
|
+
*
|
|
15
|
+
* @param TKey The type of the key for each item stored by this controller.
|
|
16
|
+
* @param T The type of the records that the controller can manage.
|
|
17
|
+
* @param TMetrics The type of the metrics that the controller can provide.
|
|
18
|
+
* @param TStore The type of the store that the controller uses.
|
|
19
|
+
* @param TRecordStore The type of the store that the controller uses for record items.
|
|
20
|
+
* @param TResult The type of the result that the controller returns to clients. Must be a subset of T.
|
|
21
|
+
*/
|
|
22
|
+
export class SubCrudRecordsController {
|
|
23
|
+
get config() {
|
|
24
|
+
return this._config;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the name of the controller.
|
|
28
|
+
*/
|
|
29
|
+
get name() {
|
|
30
|
+
return this._name;
|
|
31
|
+
}
|
|
32
|
+
get policies() {
|
|
33
|
+
return this._policies;
|
|
34
|
+
}
|
|
35
|
+
get store() {
|
|
36
|
+
return this._store;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the kind of resources that this controller is for.
|
|
40
|
+
*/
|
|
41
|
+
get resourceKind() {
|
|
42
|
+
return this._resourceKind;
|
|
43
|
+
}
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this._name = config.name;
|
|
46
|
+
this._store = config.store;
|
|
47
|
+
this._recordStore = config.recordItemStore;
|
|
48
|
+
this._policies = config.policies;
|
|
49
|
+
this._config = config.config;
|
|
50
|
+
this._resourceKind = config.resourceKind;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates or updates an item in the given record.
|
|
54
|
+
* @param request The request.
|
|
55
|
+
*/
|
|
56
|
+
async recordItem(request) {
|
|
57
|
+
try {
|
|
58
|
+
const contextResult = await this._policies.constructAuthorizationContext({
|
|
59
|
+
recordKeyOrRecordName: request.recordKeyOrRecordName,
|
|
60
|
+
userId: request.userId,
|
|
61
|
+
});
|
|
62
|
+
if (contextResult.success === false) {
|
|
63
|
+
return contextResult;
|
|
64
|
+
}
|
|
65
|
+
const recordName = contextResult.context.recordName;
|
|
66
|
+
const existingItem = await this._store.getItemByKey(recordName, request.item.address, request.item.key);
|
|
67
|
+
if (!existingItem.parentMarkers) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
errorCode: 'data_not_found',
|
|
71
|
+
errorMessage: 'The parent item was not found.',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
let resourceMarkers = existingItem.parentMarkers;
|
|
75
|
+
let action = existingItem.item
|
|
76
|
+
? 'update'
|
|
77
|
+
: 'create';
|
|
78
|
+
let authorization;
|
|
79
|
+
if (action === 'update') {
|
|
80
|
+
action = 'update';
|
|
81
|
+
authorization =
|
|
82
|
+
await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
83
|
+
userId: request.userId,
|
|
84
|
+
instances: request.instances,
|
|
85
|
+
resources: [
|
|
86
|
+
{
|
|
87
|
+
resourceKind: this._resourceKind,
|
|
88
|
+
resourceId: existingItem.item.address,
|
|
89
|
+
action: action,
|
|
90
|
+
markers: resourceMarkers,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
if (authorization.success === false) {
|
|
95
|
+
return authorization;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
authorization =
|
|
100
|
+
await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
101
|
+
userId: request.userId,
|
|
102
|
+
instances: request.instances,
|
|
103
|
+
resources: [
|
|
104
|
+
{
|
|
105
|
+
resourceKind: this._resourceKind,
|
|
106
|
+
resourceId: request.item.address,
|
|
107
|
+
action: action,
|
|
108
|
+
markers: resourceMarkers,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
if (authorization.success === false) {
|
|
113
|
+
return authorization;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!resourceMarkers) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
errorCode: 'invalid_request',
|
|
120
|
+
errorMessage: 'The item must have markers.',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const item = this._transformInputItem(request.item);
|
|
124
|
+
const subscriptionResult = await this._checkSubscriptionMetrics(action, contextResult.context, authorization, item);
|
|
125
|
+
if (subscriptionResult.success === false) {
|
|
126
|
+
return subscriptionResult;
|
|
127
|
+
}
|
|
128
|
+
const result = await this._putItem(action, recordName, item, contextResult.context, authorization, request);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
const span = trace.getActiveSpan();
|
|
133
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
134
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
135
|
+
console.error(`[${this._name}] Error recording item:`, err);
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
errorCode: 'server_error',
|
|
139
|
+
errorMessage: 'A server error occurred.',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Updates or creates the item in the given record.
|
|
145
|
+
* @param action The action that is being performed.
|
|
146
|
+
* @param recordName The name of the record.
|
|
147
|
+
* @param item The item that should be updated or created.
|
|
148
|
+
* @param context The authorization context.
|
|
149
|
+
* @param authorization The authorization for the user and instances.
|
|
150
|
+
* @param request The request.
|
|
151
|
+
*/
|
|
152
|
+
async _putItem(action, recordName, item, context, authorization, request) {
|
|
153
|
+
const crudResult = await this._store.putItem(recordName, item);
|
|
154
|
+
if (crudResult.success === false) {
|
|
155
|
+
return crudResult;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
recordName,
|
|
160
|
+
address: item.address,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Gets the item with the given address from the given record.
|
|
165
|
+
* @param request The request to get the item.
|
|
166
|
+
*/
|
|
167
|
+
async getItem(request) {
|
|
168
|
+
try {
|
|
169
|
+
const baseRequest = {
|
|
170
|
+
recordKeyOrRecordName: request.recordName,
|
|
171
|
+
userId: request.userId,
|
|
172
|
+
instances: request.instances,
|
|
173
|
+
};
|
|
174
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
175
|
+
if (context.success === false) {
|
|
176
|
+
return context;
|
|
177
|
+
}
|
|
178
|
+
const result = await this._store.getItemByKey(context.context.recordName, request.address, request.key);
|
|
179
|
+
if (!result.item) {
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
errorCode: 'data_not_found',
|
|
183
|
+
errorMessage: 'The item was not found.',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const markers = result.parentMarkers;
|
|
187
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
188
|
+
userId: request.userId,
|
|
189
|
+
instances: request.instances,
|
|
190
|
+
resourceKind: this._resourceKind,
|
|
191
|
+
resourceId: request.address,
|
|
192
|
+
action: 'read',
|
|
193
|
+
markers: markers,
|
|
194
|
+
});
|
|
195
|
+
if (authorization.success === false) {
|
|
196
|
+
return authorization;
|
|
197
|
+
}
|
|
198
|
+
const item = result.item;
|
|
199
|
+
const metricsResult = await this._checkSubscriptionMetrics('read', context.context, authorization, item);
|
|
200
|
+
if (metricsResult.success === false) {
|
|
201
|
+
return metricsResult;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
success: true,
|
|
205
|
+
item: this._convertItemToResult(item, context.context),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
const span = trace.getActiveSpan();
|
|
210
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
211
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
212
|
+
console.error(`[${this._name}] Error getting item:`, err);
|
|
213
|
+
return {
|
|
214
|
+
success: false,
|
|
215
|
+
errorCode: 'server_error',
|
|
216
|
+
errorMessage: 'A server error occurred.',
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Deletes the item with the given address from the given record.
|
|
222
|
+
* @param request The request.
|
|
223
|
+
*/
|
|
224
|
+
async eraseItem(request) {
|
|
225
|
+
try {
|
|
226
|
+
const context = await this._policies.constructAuthorizationContext({
|
|
227
|
+
recordKeyOrRecordName: request.recordName,
|
|
228
|
+
userId: request.userId,
|
|
229
|
+
});
|
|
230
|
+
if (context.success === false) {
|
|
231
|
+
return context;
|
|
232
|
+
}
|
|
233
|
+
const result = await this._store.getItemByKey(context.context.recordName, request.address, request.key);
|
|
234
|
+
if (!result.item) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
errorCode: 'data_not_found',
|
|
238
|
+
errorMessage: 'The item was not found.',
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const markers = result.parentMarkers;
|
|
242
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
243
|
+
userId: request.userId,
|
|
244
|
+
instances: request.instances,
|
|
245
|
+
resourceKind: this._resourceKind,
|
|
246
|
+
resourceId: request.address,
|
|
247
|
+
action: 'delete',
|
|
248
|
+
markers,
|
|
249
|
+
});
|
|
250
|
+
if (authorization.success === false) {
|
|
251
|
+
return authorization;
|
|
252
|
+
}
|
|
253
|
+
const recordName = context.context.recordName;
|
|
254
|
+
const subscriptionResult = await this._checkSubscriptionMetrics('delete', context.context, authorization);
|
|
255
|
+
if (subscriptionResult.success === false) {
|
|
256
|
+
return subscriptionResult;
|
|
257
|
+
}
|
|
258
|
+
await this._store.deleteItem(recordName, request.address, request.key);
|
|
259
|
+
return {
|
|
260
|
+
success: true,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
const span = trace.getActiveSpan();
|
|
265
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
266
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
267
|
+
console.error(`[${this._name}] Error erasing item:`, err);
|
|
268
|
+
return {
|
|
269
|
+
success: false,
|
|
270
|
+
errorCode: 'server_error',
|
|
271
|
+
errorMessage: 'A server error occurred.',
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Lists items in the given record.
|
|
277
|
+
* @param request The request.
|
|
278
|
+
*/
|
|
279
|
+
async listItems(request) {
|
|
280
|
+
try {
|
|
281
|
+
const baseRequest = {
|
|
282
|
+
recordKeyOrRecordName: request.recordName,
|
|
283
|
+
userId: request.userId,
|
|
284
|
+
instances: request.instances,
|
|
285
|
+
};
|
|
286
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
287
|
+
if (context.success === false) {
|
|
288
|
+
return context;
|
|
289
|
+
}
|
|
290
|
+
const recordName = context.context.recordName;
|
|
291
|
+
const item = await this._recordStore.getItemByAddress(recordName, request.address);
|
|
292
|
+
if (!item) {
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
errorCode: 'data_not_found',
|
|
296
|
+
errorMessage: 'The parent item was not found.',
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
300
|
+
userId: request.userId,
|
|
301
|
+
instances: request.instances,
|
|
302
|
+
resourceKind: this._resourceKind,
|
|
303
|
+
action: 'list',
|
|
304
|
+
markers: item.markers,
|
|
305
|
+
});
|
|
306
|
+
if (authorization.success === false) {
|
|
307
|
+
return authorization;
|
|
308
|
+
}
|
|
309
|
+
const result2 = await this._store.listItems(context.context.recordName, request.address);
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
recordName: context.context.recordName,
|
|
313
|
+
items: result2.items.map((item) => this._convertItemToResult(item, context.context)),
|
|
314
|
+
totalCount: result2.totalCount,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
const span = trace.getActiveSpan();
|
|
319
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
320
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
321
|
+
console.error(`[${this._name}] Error listing items:`, err);
|
|
322
|
+
return {
|
|
323
|
+
success: false,
|
|
324
|
+
errorCode: 'server_error',
|
|
325
|
+
errorMessage: 'A server error occurred.',
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Converts the given item to a version that is able to be returned to clients.
|
|
331
|
+
* Can be overriden to ensure that some fields are not returned.
|
|
332
|
+
* @param item The item that should be converted.
|
|
333
|
+
* @param context The authorization context.
|
|
334
|
+
* @returns The converted item.
|
|
335
|
+
*/
|
|
336
|
+
_convertItemToResult(item, context) {
|
|
337
|
+
return item;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Transforms the given input item and returns the transformed item.
|
|
341
|
+
* Useful for transforming items before they are stored.
|
|
342
|
+
* @param item The item that should be transformed.
|
|
343
|
+
*/
|
|
344
|
+
_transformInputItem(item) {
|
|
345
|
+
return item;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
__decorate([
|
|
349
|
+
traced(TRACE_NAME)
|
|
350
|
+
], SubCrudRecordsController.prototype, "recordItem", null);
|
|
351
|
+
__decorate([
|
|
352
|
+
traced(TRACE_NAME)
|
|
353
|
+
], SubCrudRecordsController.prototype, "getItem", null);
|
|
354
|
+
__decorate([
|
|
355
|
+
traced(TRACE_NAME)
|
|
356
|
+
], SubCrudRecordsController.prototype, "eraseItem", null);
|
|
357
|
+
__decorate([
|
|
358
|
+
traced(TRACE_NAME)
|
|
359
|
+
], SubCrudRecordsController.prototype, "listItems", null);
|
|
360
|
+
//# sourceMappingURL=SubCrudRecordsController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubCrudRecordsController.js","sourceRoot":"","sources":["SubCrudRecordsController.ts"],"names":[],"mappings":";;;;;;AA4BA,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAiD3D,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,wBAAwB;IAc1C,IAAc,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,IAAc,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAc,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QAC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AY,EAAE,0BAA0B;aAC3C,CAAC;QACN,CAAC;IACL,CAAC;IAkBD;;;;;;OAMG;IACO,oBAAoB,CAC1B,IAAO,EACP,OAA6B;QAE7B,OAAO,IAA0B,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACO,mBAAmB,CAAC,IAAO;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAxbS;IADL,MAAM,CAAC,UAAU,CAAC;0DA0HlB;AAqCK;IADL,MAAM,CAAC,UAAU,CAAC;uDA+ElB;AAOK;IADL,MAAM,CAAC,UAAU,CAAC;yDA+ElB;AAOK;IADL,MAAM,CAAC,UAAU,CAAC;yDAyElB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MemoryStore } from '../../MemoryStore';
|
|
2
|
+
import type { SubCrudRecordsConfiguration, SubCrudRecordsController } from './SubCrudRecordsController';
|
|
3
|
+
import type { CrudRecord, CrudRecordsStore } from '../CrudRecordsStore';
|
|
4
|
+
import { createTestControllers } from '../../TestUtils';
|
|
5
|
+
import type { ActionKinds, ResourceKinds } from '@casual-simulation/aux-common';
|
|
6
|
+
import type { SubCrudRecord, SubCrudRecordsStore } from './SubCrudRecordsStore';
|
|
7
|
+
export type TestControllers = ReturnType<typeof createTestControllers>;
|
|
8
|
+
export type TestControllerConfiguration<TKey, TItem extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, TItem>, TRecordStore extends CrudRecordsStore<CrudRecord>> = Omit<SubCrudRecordsConfiguration<TKey, TItem, TStore, TRecordStore>, 'resourceKind' | 'allowRecordKeys' | 'name'>;
|
|
9
|
+
export interface TestContext<TKey, TItem extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, TItem>, TRecordStore extends CrudRecordsStore<CrudRecord>, TController extends SubCrudRecordsController<TKey, TItem, TStore, TRecordStore>> {
|
|
10
|
+
services: TestControllers;
|
|
11
|
+
store: MemoryStore;
|
|
12
|
+
itemsStore: TStore;
|
|
13
|
+
recordItemsStore: TRecordStore;
|
|
14
|
+
manager: TController;
|
|
15
|
+
userId: string;
|
|
16
|
+
sessionKey: string;
|
|
17
|
+
otherUserId: string;
|
|
18
|
+
key: string;
|
|
19
|
+
subjectlessKey: string;
|
|
20
|
+
recordName: string;
|
|
21
|
+
connectionKey: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new test context that can be used to test a CRUD records controller.
|
|
25
|
+
* @param storeFactory The factory function that creates the store.
|
|
26
|
+
* @param controllerFactory The factory function that creates the controller.
|
|
27
|
+
*/
|
|
28
|
+
export declare function setupTestContext<TKey, TItem extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, TItem>, TRecordStore extends CrudRecordsStore<CrudRecord>, TController extends SubCrudRecordsController<TKey, TItem, TStore, TRecordStore>>(recordStoreFactory: (services: TestControllers) => TRecordStore, storeFactory: (services: TestControllers, recordStore: TRecordStore) => TStore, controllerFactory: (config: TestControllerConfiguration<TKey, TItem, TStore, TRecordStore>, services: TestControllers) => TController): Promise<TestContext<TKey, TItem, TStore, TRecordStore, TController>>;
|
|
29
|
+
/**
|
|
30
|
+
* Runs all of the common tests for a CRUD records controller.
|
|
31
|
+
* @param allowRecordKeys Whether record keys can be used to access the resources.
|
|
32
|
+
* @param resourceKind The resource kind that should be expected.
|
|
33
|
+
* @param storeFactory The factory function that creates the store.
|
|
34
|
+
* @param controllerFactory The factory function that creates the controller.
|
|
35
|
+
* @param createTestItem The factory function that creates a test item.
|
|
36
|
+
* @param configureEnvironment An optional function that can be used to configure the environment before the tests are run.
|
|
37
|
+
*/
|
|
38
|
+
export declare function testCrudRecordsController<TKey, TItem extends SubCrudRecord<TKey>, TStore extends SubCrudRecordsStore<TKey, TItem>, TRecordStore extends CrudRecordsStore<CrudRecord>, TController extends SubCrudRecordsController<TKey, TItem, TStore, TRecordStore>>(allowRecordKeys: boolean, resourceKind: ResourceKinds, recordStoreFactory: (services: TestControllers) => TRecordStore, storeFactory: (services: TestControllers, recordStore: TRecordStore) => TStore, controllerFactory: (config: TestControllerConfiguration<TKey, TItem, TStore, TRecordStore>, services: TestControllers) => TController, createKey: (id: number) => TKey, createTestItem: (item: SubCrudRecord<TKey>) => TItem, createRecordItem: (item: CrudRecord) => CrudRecord, configureEnvironment?: (context: TestContext<TKey, TItem, TStore, TRecordStore, TController>) => Promise<void>, allowedActions?: ActionKinds[]): void;
|
|
39
|
+
//# sourceMappingURL=SubCrudRecordsControllerTests.d.ts.map
|