@liminalfunctions/framework 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +5 -0
- package/dist/F_Client_Collection_Registry.d.ts +18 -0
- package/dist/F_Client_Collection_Registry.js +36 -0
- package/dist/F_Client_Collection_Registry.js.map +1 -0
- package/dist/F_Collection.d.ts +21 -0
- package/dist/F_Collection.js +36 -0
- package/dist/F_Collection.js.map +1 -0
- package/dist/F_Collection_Registry.d.ts +11 -0
- package/dist/F_Collection_Registry.js +18 -0
- package/dist/F_Collection_Registry.js.map +1 -0
- package/dist/F_Compile.d.ts +4 -0
- package/dist/F_Compile.js +298 -0
- package/dist/F_Compile.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Open_Access.d.ts +11 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js +14 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Ownership.d.ts +12 -0
- package/dist/F_Security_Models/F_SM_Ownership.js +46 -0
- package/dist/F_Security_Models/F_SM_Ownership.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.d.ts +19 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js +73 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js.map +1 -0
- package/dist/F_Security_Models/F_Security_Model.d.ts +41 -0
- package/dist/F_Security_Models/F_Security_Model.js +29 -0
- package/dist/F_Security_Models/F_Security_Model.js.map +1 -0
- package/dist/code_generation/generate_client_library.d.ts +4 -0
- package/dist/code_generation/generate_client_library.js +158 -0
- package/dist/code_generation/generate_client_library.js.map +1 -0
- package/dist/code_generation/templates/.gitignore.mustache +383 -0
- package/dist/code_generation/templates/collection.mustache +106 -0
- package/dist/code_generation/templates/main.mustache +24 -0
- package/dist/code_generation/templates/package.json.mustache +18 -0
- package/dist/code_generation/templates/tsconfig.json.mustache +14 -0
- package/dist/code_generation/templates/types.mustache +4 -0
- package/dist/code_generation/templates/utils.ts.mustache +17 -0
- package/dist/code_generation/utils/tab_indent.d.ts +1 -0
- package/dist/code_generation/utils/tab_indent.js +4 -0
- package/dist/code_generation/utils/tab_indent.js.map +1 -0
- package/dist/code_generation/utils/type_from_zod.d.ts +2 -0
- package/dist/code_generation/utils/type_from_zod.js +102 -0
- package/dist/code_generation/utils/type_from_zod.js.map +1 -0
- package/dist/utils/cache.d.ts +13 -0
- package/dist/utils/cache.js +101 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/mongoose_from_zod.d.ts +13 -0
- package/dist/utils/mongoose_from_zod.js +164 -0
- package/dist/utils/mongoose_from_zod.js.map +1 -0
- package/dist/utils/pretty_print_zod.d.ts +2 -0
- package/dist/utils/pretty_print_zod.js +63 -0
- package/dist/utils/pretty_print_zod.js.map +1 -0
- package/dist/utils/query_object_to_mongodb_query.d.ts +3 -0
- package/dist/utils/query_object_to_mongodb_query.js +61 -0
- package/dist/utils/query_object_to_mongodb_query.js.map +1 -0
- package/dist/utils/query_validator_from_zod.d.ts +6 -0
- package/dist/utils/query_validator_from_zod.js +216 -0
- package/dist/utils/query_validator_from_zod.js.map +1 -0
- package/package.json +36 -0
- package/src/F_Collection.ts +50 -0
- package/src/F_Collection_Registry.ts +29 -0
- package/src/F_Compile.ts +368 -0
- package/src/F_Security_Models/F_SM_Open_Access.ts +21 -0
- package/src/F_Security_Models/F_SM_Ownership.ts +72 -0
- package/src/F_Security_Models/F_SM_Role_Membership.ts +87 -0
- package/src/F_Security_Models/F_Security_Model.ts +85 -0
- package/src/code_generation/generate_client_library.ts +197 -0
- package/src/code_generation/templates/.gitignore.mustache +383 -0
- package/src/code_generation/templates/collection.mustache +106 -0
- package/src/code_generation/templates/main.mustache +24 -0
- package/src/code_generation/templates/package.json.mustache +18 -0
- package/src/code_generation/templates/tsconfig.json.mustache +14 -0
- package/src/code_generation/templates/types.mustache +4 -0
- package/src/code_generation/templates/utils.ts.mustache +17 -0
- package/src/code_generation/utils/tab_indent.ts +3 -0
- package/src/code_generation/utils/type_from_zod.ts +140 -0
- package/src/utils/cache.ts +149 -0
- package/src/utils/mongoose_from_zod.ts +191 -0
- package/src/utils/pretty_print_zod.ts +75 -0
- package/src/utils/query_object_to_mongodb_query.ts +73 -0
- package/src/utils/query_validator_from_zod.ts +246 -0
- package/test/0_0_mongoose_from_zod.test.ts +260 -0
- package/test/0_1_query_validator_from_zod.test.ts +518 -0
- package/test/0_2_query_validator_to_mongodb_query.test.ts +365 -0
- package/test/0_3_cache.test.ts +204 -0
- package/test/1_0_basic_server.test.ts +530 -0
- package/test/1_1_security_ownership.test.ts +328 -0
- package/test/1_2_role_membership.test.ts +731 -0
- package/test/2_0_client_library_basic_type_generation.test.ts +444 -0
- package/test/2_0_client_library_query_type_generation.test.ts +352 -0
- package/test/2_1_client_library_generation.test.ts +255 -0
- package/test/tmp/dist/Brief_News_Category.d.ts +16 -0
- package/test/tmp/dist/Brief_News_Category.js +85 -0
- package/test/tmp/dist/Brief_News_Category.js.map +1 -0
- package/test/tmp/dist/Client.d.ts +19 -0
- package/test/tmp/dist/Client.js +97 -0
- package/test/tmp/dist/Client.js.map +1 -0
- package/test/tmp/dist/Institution.d.ts +18 -0
- package/test/tmp/dist/Institution.js +94 -0
- package/test/tmp/dist/Institution.js.map +1 -0
- package/test/tmp/dist/Project.d.ts +16 -0
- package/test/tmp/dist/Project.js +85 -0
- package/test/tmp/dist/Project.js.map +1 -0
- package/test/tmp/dist/index.d.ts +4 -0
- package/test/tmp/dist/index.js +14 -0
- package/test/tmp/dist/index.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category.js +2 -0
- package/test/tmp/dist/types/brief_news_category.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_post.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_post.js +2 -0
- package/test/tmp/dist/types/brief_news_category_post.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_put.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_put.js +2 -0
- package/test/tmp/dist/types/brief_news_category_put.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_query.d.ts +26 -0
- package/test/tmp/dist/types/brief_news_category_query.js +2 -0
- package/test/tmp/dist/types/brief_news_category_query.js.map +1 -0
- package/test/tmp/dist/types/client.d.ts +5 -0
- package/test/tmp/dist/types/client.js +2 -0
- package/test/tmp/dist/types/client.js.map +1 -0
- package/test/tmp/dist/types/client_post.d.ts +5 -0
- package/test/tmp/dist/types/client_post.js +2 -0
- package/test/tmp/dist/types/client_post.js.map +1 -0
- package/test/tmp/dist/types/client_put.d.ts +5 -0
- package/test/tmp/dist/types/client_put.js +2 -0
- package/test/tmp/dist/types/client_put.js.map +1 -0
- package/test/tmp/dist/types/client_query.d.ts +18 -0
- package/test/tmp/dist/types/client_query.js +2 -0
- package/test/tmp/dist/types/client_query.js.map +1 -0
- package/test/tmp/dist/types/institution.d.ts +4 -0
- package/test/tmp/dist/types/institution.js +2 -0
- package/test/tmp/dist/types/institution.js.map +1 -0
- package/test/tmp/dist/types/institution_post.d.ts +4 -0
- package/test/tmp/dist/types/institution_post.js +2 -0
- package/test/tmp/dist/types/institution_post.js.map +1 -0
- package/test/tmp/dist/types/institution_put.d.ts +4 -0
- package/test/tmp/dist/types/institution_put.js +2 -0
- package/test/tmp/dist/types/institution_put.js.map +1 -0
- package/test/tmp/dist/types/institution_query.d.ts +14 -0
- package/test/tmp/dist/types/institution_query.js +2 -0
- package/test/tmp/dist/types/institution_query.js.map +1 -0
- package/test/tmp/dist/types/project.d.ts +7 -0
- package/test/tmp/dist/types/project.js +2 -0
- package/test/tmp/dist/types/project.js.map +1 -0
- package/test/tmp/dist/types/project_post.d.ts +7 -0
- package/test/tmp/dist/types/project_post.js +2 -0
- package/test/tmp/dist/types/project_post.js.map +1 -0
- package/test/tmp/dist/types/project_put.d.ts +7 -0
- package/test/tmp/dist/types/project_put.js +2 -0
- package/test/tmp/dist/types/project_put.js.map +1 -0
- package/test/tmp/dist/types/project_query.d.ts +27 -0
- package/test/tmp/dist/types/project_query.js +2 -0
- package/test/tmp/dist/types/project_query.js.map +1 -0
- package/test/tmp/dist/utils/utils.d.ts +11 -0
- package/test/tmp/dist/utils/utils.js +13 -0
- package/test/tmp/dist/utils/utils.js.map +1 -0
- package/test/tmp/package-lock.json +573 -0
- package/test/tmp/package.json +18 -0
- package/test/tmp/src/Brief_News_Category.ts +94 -0
- package/test/tmp/src/Client.ts +106 -0
- package/test/tmp/src/Institution.ts +103 -0
- package/test/tmp/src/Project.ts +94 -0
- package/test/tmp/src/index.ts +20 -0
- package/test/tmp/src/types/brief_news_category.ts +7 -0
- package/test/tmp/src/types/brief_news_category_post.ts +7 -0
- package/test/tmp/src/types/brief_news_category_put.ts +7 -0
- package/test/tmp/src/types/brief_news_category_query.ts +26 -0
- package/test/tmp/src/types/client.ts +5 -0
- package/test/tmp/src/types/client_post.ts +5 -0
- package/test/tmp/src/types/client_put.ts +5 -0
- package/test/tmp/src/types/client_query.ts +18 -0
- package/test/tmp/src/types/institution.ts +4 -0
- package/test/tmp/src/types/institution_post.ts +4 -0
- package/test/tmp/src/types/institution_put.ts +4 -0
- package/test/tmp/src/types/institution_query.ts +14 -0
- package/test/tmp/src/types/project.ts +7 -0
- package/test/tmp/src/types/project_post.ts +7 -0
- package/test/tmp/src/types/project_put.ts +7 -0
- package/test/tmp/src/types/project_query.ts +27 -0
- package/test/tmp/src/utils/utils.ts +17 -0
- package/test/tmp/tsconfig.json +14 -0
- package/tsconfig.json +14 -0
package/.mocharc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { F_Collection } from './F_Collection.js';
|
|
3
|
+
export declare class F_Layer<Layer_ID extends string, Layers = {}, Collections = {}> {
|
|
4
|
+
path: string[];
|
|
5
|
+
layer_id: Layer_ID;
|
|
6
|
+
collections: Collections;
|
|
7
|
+
layers: Layers;
|
|
8
|
+
constructor(layer_id: Layer_ID);
|
|
9
|
+
add_layer<Child_Layer_ID extends string, Child_Layers, Child_Collections>(layer: F_Layer<Child_Layer_ID, Child_Layers, Child_Collections>): F_Layer<Layer_ID, Layers & {
|
|
10
|
+
[key in Child_Layer_ID]: F_Layer<Child_Layer_ID, Child_Layers, Child_Collections>;
|
|
11
|
+
}, Collections>;
|
|
12
|
+
add_collection<Collection_ID extends string, ZodSchema extends z.ZodObject>(collection: F_Collection<Collection_ID, ZodSchema>): F_Layer<Layer_ID, Layers, Collections & {
|
|
13
|
+
[key in Collection_ID]: F_Collection<Collection_ID, ZodSchema>;
|
|
14
|
+
}>;
|
|
15
|
+
clone(): typeof this;
|
|
16
|
+
layer<Layer_ID extends keyof Layers>(layer_id: Layer_ID): Layers[Layer_ID];
|
|
17
|
+
collection<Collection_ID extends keyof Collections>(collection_id: Collection_ID): Collections[Collection_ID];
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class F_Layer {
|
|
2
|
+
path;
|
|
3
|
+
layer_id;
|
|
4
|
+
collections;
|
|
5
|
+
layers;
|
|
6
|
+
constructor(layer_id) {
|
|
7
|
+
this.layer_id = layer_id;
|
|
8
|
+
this.collections = {};
|
|
9
|
+
this.layers = {};
|
|
10
|
+
}
|
|
11
|
+
add_layer(layer) {
|
|
12
|
+
let result = this.clone();
|
|
13
|
+
result.layers[layer.layer_id] = layer;
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
add_collection(collection) {
|
|
17
|
+
let result = this.clone();
|
|
18
|
+
result.collections[collection.collection_id] = collection;
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
let clone = new F_Layer(this.layer_id);
|
|
23
|
+
clone.collections = Object.assign({}, this.collections);
|
|
24
|
+
for (let [child_layer_id, child_layer] of Object.entries(this.layers)) {
|
|
25
|
+
clone.layers[child_layer_id] = child_layer.clone();
|
|
26
|
+
}
|
|
27
|
+
return clone;
|
|
28
|
+
}
|
|
29
|
+
layer(layer_id) {
|
|
30
|
+
return this.layers[layer_id];
|
|
31
|
+
}
|
|
32
|
+
collection(collection_id) {
|
|
33
|
+
return this.collections[collection_id];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=F_Client_Collection_Registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"F_Client_Collection_Registry.js","sourceRoot":"","sources":["../src/F_Client_Collection_Registry.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,OAAO;IAChB,IAAI,CAAU;IACd,QAAQ,CAAU;IAClB,WAAW,CAAc;IACzB,MAAM,CAAS;IAEf,YAAY,QAAkB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,EAAiB,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,EAAY,CAAC;IAC/B,CAAC;IAED,SAAS,CAAiE,KAA+D;QAMrI,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,EAItB,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QACtC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,cAAc,CAA8D,UAAkD;QAM1H,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,EAItB,CAAC;QAEF,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC;QAC1D,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK;QACD,IAAI,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAgB,CAAC;QACtD,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxD,KAAI,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,CAAC;YAElE,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC;QACvD,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,CAAgC,QAAkB;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,UAAU,CAA0C,aAA4B;QAC5E,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC3C,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { Model } from "mongoose";
|
|
3
|
+
import { F_Security_Model } from "./F_Security_Models/F_Security_Model.js";
|
|
4
|
+
export type F_Layer<Collection_ID extends string, ZodSchema extends z.ZodObject> = {
|
|
5
|
+
layers: string[];
|
|
6
|
+
security_models: F_Security_Model<Collection_ID, ZodSchema>[];
|
|
7
|
+
};
|
|
8
|
+
export declare class F_Collection<Collection_ID extends string, ZodSchema extends z.ZodObject> {
|
|
9
|
+
collection_id: Collection_ID;
|
|
10
|
+
validator: ZodSchema;
|
|
11
|
+
mongoose_schema: any;
|
|
12
|
+
mongoose_model: Model<z.infer<ZodSchema>>;
|
|
13
|
+
query_validator_server: z.ZodType;
|
|
14
|
+
query_validator_client: z.ZodType;
|
|
15
|
+
put_validator: z.ZodType;
|
|
16
|
+
post_validator: z.ZodType;
|
|
17
|
+
is_compiled: boolean;
|
|
18
|
+
access_layers: F_Layer<Collection_ID, ZodSchema>[];
|
|
19
|
+
constructor(collection_name: Collection_ID, validator: ZodSchema);
|
|
20
|
+
add_layers(layers: string[], security_models: F_Security_Model<Collection_ID, ZodSchema>[], is_layer_owner?: boolean): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mongoose_from_zod, schema_from_zod } from "./utils/mongoose_from_zod.js";
|
|
2
|
+
import { query_validator_from_zod } from "./utils/query_validator_from_zod.js";
|
|
3
|
+
export class F_Collection {
|
|
4
|
+
collection_id;
|
|
5
|
+
validator;
|
|
6
|
+
mongoose_schema;
|
|
7
|
+
mongoose_model;
|
|
8
|
+
query_validator_server;
|
|
9
|
+
query_validator_client;
|
|
10
|
+
put_validator;
|
|
11
|
+
post_validator;
|
|
12
|
+
is_compiled;
|
|
13
|
+
access_layers;
|
|
14
|
+
constructor(collection_name, validator) {
|
|
15
|
+
this.collection_id = collection_name;
|
|
16
|
+
this.validator = validator;
|
|
17
|
+
this.mongoose_schema = schema_from_zod(validator);
|
|
18
|
+
this.mongoose_model = mongoose_from_zod(collection_name, validator);
|
|
19
|
+
this.query_validator_server = query_validator_from_zod(validator, 'server');
|
|
20
|
+
this.query_validator_client = query_validator_from_zod(validator, 'client');
|
|
21
|
+
this.put_validator = validator.partial();
|
|
22
|
+
this.post_validator = Object.hasOwn(this.validator._zod.def.shape, '_id') ? validator.partial({ _id: true }) : validator;
|
|
23
|
+
this.access_layers = [];
|
|
24
|
+
this.is_compiled = false;
|
|
25
|
+
}
|
|
26
|
+
add_layers(layers, security_models, is_layer_owner = false) {
|
|
27
|
+
if (this.is_compiled) {
|
|
28
|
+
throw new Error(`Manipulating a model post-compilation doesn't work.`);
|
|
29
|
+
}
|
|
30
|
+
this.access_layers.push({
|
|
31
|
+
layers: layers,
|
|
32
|
+
security_models: security_models
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=F_Collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"F_Collection.js","sourceRoot":"","sources":["../src/F_Collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGlF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAQ/E,MAAM,OAAO,YAAY;IACrB,aAAa,CAAgB;IAC7B,SAAS,CAAY;IACrB,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ACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { F_Collection } from './F_Collection.js';
|
|
3
|
+
import { Router } from 'express';
|
|
4
|
+
export declare class F_Collection_Registry<Collections = {}> {
|
|
5
|
+
collections: Collections;
|
|
6
|
+
constructor();
|
|
7
|
+
register<Collection_ID extends string, ZodSchema extends z.ZodObject>(collection: F_Collection<Collection_ID, ZodSchema>): F_Collection_Registry<Collections & {
|
|
8
|
+
[key in Collection_ID]: F_Collection<Collection_ID, ZodSchema>;
|
|
9
|
+
}>;
|
|
10
|
+
compile(app: Router, api_prefix: string): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { compile } from './F_Compile.js';
|
|
2
|
+
export class F_Collection_Registry {
|
|
3
|
+
collections;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.collections = {};
|
|
6
|
+
}
|
|
7
|
+
register(collection) {
|
|
8
|
+
let collections = this.collections;
|
|
9
|
+
collections[collection.collection_id] = collection;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
compile(app, api_prefix) {
|
|
13
|
+
for (let collection of Object.values(this.collections)) {
|
|
14
|
+
compile(app, collection, api_prefix);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=F_Collection_Registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"F_Collection_Registry.js","sourceRoot":"","sources":["../src/F_Collection_Registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,gBAAgB,CAAA;AAKxD,MAAM,OAAO,qBAAqB;IAC9B,WAAW,CAAc;IAIzB;QACI,IAAI,CAAC,WAAW,GAAG,EAAiB,CAAC;IACzC,CAAC;IAED,QAAQ,CAA8D,UAAkD;QACpH,IAAI,WAAW,GAAG,IAAI,CAAC,WAA8F,CAAC;QAEtH,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC;QACnD,OAAO,IAA8G,CAAC;IAC1H,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,UAAkB;QACnC,KAAI,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAC,CAAC;YACnD,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;QACxC,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
import { F_Collection } from "./F_Collection.js";
|
|
4
|
+
export declare function compile<Collection_ID extends string, ZodSchema extends z.ZodObject>(app: Router, collection: F_Collection<Collection_ID, ZodSchema>, api_prefix: string): void;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { isValidObjectId } from "mongoose";
|
|
3
|
+
import { F_Security_Model } from "./F_Security_Models/F_Security_Model.js";
|
|
4
|
+
import { query_object_to_mongodb_limits, query_object_to_mongodb_query } from "./utils/query_object_to_mongodb_query.js";
|
|
5
|
+
export function compile(app, collection, api_prefix) {
|
|
6
|
+
for (let access_layers of collection.access_layers) {
|
|
7
|
+
let base_layers_path_components = access_layers.layers.flatMap(ele => [ele, ':' + ele]);
|
|
8
|
+
let get_one_path = [
|
|
9
|
+
api_prefix,
|
|
10
|
+
...base_layers_path_components,
|
|
11
|
+
`${collection.collection_id}/:document_id`
|
|
12
|
+
].join('/');
|
|
13
|
+
app.get(get_one_path, async (req, res) => {
|
|
14
|
+
if (!isValidObjectId(req.params.document_id)) {
|
|
15
|
+
res.status(400);
|
|
16
|
+
res.json({ error: `${req.params.document_id} is not a valid document ID.` });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let find = { '_id': req.params.document_id };
|
|
20
|
+
for (let layer of access_layers.layers) {
|
|
21
|
+
find[`${layer}_id`] = req.params[layer];
|
|
22
|
+
}
|
|
23
|
+
let permissive_security_model = await F_Security_Model.model_with_permission(access_layers.security_models, req, res, find, 'get');
|
|
24
|
+
if (!permissive_security_model) {
|
|
25
|
+
res.status(403);
|
|
26
|
+
res.json({ error: `You do not have permission to fetch documents from ${req.params.document_type}.` });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let document;
|
|
30
|
+
try {
|
|
31
|
+
document = await collection.mongoose_model.findOne(find, undefined, { 'lean': true });
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
res.status(500);
|
|
35
|
+
res.json({ error: `there was a novel error` });
|
|
36
|
+
console.error(err);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!document) {
|
|
40
|
+
let sendable = await permissive_security_model.handle_empty_query_results(req, res, 'get');
|
|
41
|
+
res.json(sendable);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
res.json({ data: document });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
let get_multiple_path = [
|
|
48
|
+
api_prefix,
|
|
49
|
+
...base_layers_path_components,
|
|
50
|
+
collection.collection_id
|
|
51
|
+
].join('/');
|
|
52
|
+
app.get(get_multiple_path, async (req, res) => {
|
|
53
|
+
let validated_query_args;
|
|
54
|
+
try {
|
|
55
|
+
validated_query_args = collection.query_validator_server.parse(req.query);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (err instanceof z.ZodError) {
|
|
59
|
+
res.status(400);
|
|
60
|
+
res.json({ error: err.issues });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.error(err);
|
|
65
|
+
res.status(500);
|
|
66
|
+
res.json({ error: `there was a novel error` });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let find = query_object_to_mongodb_query(validated_query_args);
|
|
71
|
+
for (let layer of access_layers.layers) {
|
|
72
|
+
find[`${layer}_id`] = req.params[layer];
|
|
73
|
+
}
|
|
74
|
+
let permissive_security_model = await F_Security_Model.model_with_permission(access_layers.security_models, req, res, find, 'get');
|
|
75
|
+
if (!permissive_security_model) {
|
|
76
|
+
res.status(403);
|
|
77
|
+
res.json({ error: `You do not have permission to fetch documents from ${req.params.document_type}.` });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let documents;
|
|
81
|
+
try {
|
|
82
|
+
let query = collection.mongoose_model.find(find, undefined, { 'lean': true });
|
|
83
|
+
let fetch = query_object_to_mongodb_limits(query, collection.query_validator_server);
|
|
84
|
+
documents = await fetch;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err.name == 'CastError') {
|
|
88
|
+
res.status(400);
|
|
89
|
+
res.json({ error: 'one of the IDs you passed to the query was not a valid MongoDB object ID.' });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
res.status(500);
|
|
94
|
+
res.send({ error: 'there was a novel error' });
|
|
95
|
+
console.error(err);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!documents) {
|
|
100
|
+
let sendable = await permissive_security_model.handle_empty_query_results(req, res, 'get');
|
|
101
|
+
res.json(sendable);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
res.json({ data: documents });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
let put_path = [
|
|
108
|
+
api_prefix,
|
|
109
|
+
...base_layers_path_components,
|
|
110
|
+
`${collection.collection_id}/:document_id`
|
|
111
|
+
].join('/');
|
|
112
|
+
app.put(put_path, async (req, res) => {
|
|
113
|
+
if (!isValidObjectId(req.params.document_id)) {
|
|
114
|
+
res.status(400);
|
|
115
|
+
res.json({ error: `${req.params.document_id} is not a valid document ID.` });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
let find = { '_id': req.params.document_id };
|
|
119
|
+
for (let layer of access_layers.layers) {
|
|
120
|
+
find[`${layer}_id`] = req.params[layer];
|
|
121
|
+
}
|
|
122
|
+
let permissive_security_model = await F_Security_Model.model_with_permission(access_layers.security_models, req, res, find, 'update');
|
|
123
|
+
if (!permissive_security_model) {
|
|
124
|
+
res.status(403);
|
|
125
|
+
res.json({ error: `You do not have permission to fetch documents from ${req.params.document_type}.` });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (collection.mongoose_schema.updated_by?.type === String) {
|
|
129
|
+
if (req.auth?.user_id) {
|
|
130
|
+
req.body.updated_by = req.auth?.user_id;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
req.body.updated_by = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (collection.mongoose_schema.updated_at?.type === Date) {
|
|
137
|
+
req.body.updated_at = new Date();
|
|
138
|
+
}
|
|
139
|
+
let validated_request_body;
|
|
140
|
+
try {
|
|
141
|
+
validated_request_body = await collection.put_validator.parse(req.body);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (err instanceof z.ZodError) {
|
|
145
|
+
res.status(400);
|
|
146
|
+
res.json({ error: err.issues });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.error(err);
|
|
151
|
+
res.status(500);
|
|
152
|
+
res.json({ error: `there was a novel error` });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (let layer of access_layers.layers) {
|
|
157
|
+
if (validated_request_body[`${layer}_id`] && validated_request_body[`${layer}_id`] !== req.params[layer]) {
|
|
158
|
+
res.status(403);
|
|
159
|
+
res.json({ error: `The system does not support changing the ${layer}_id of the document with this endpoint.` });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let results;
|
|
164
|
+
try {
|
|
165
|
+
results = await collection.mongoose_model.findOneAndUpdate(find, validated_request_body, { returnDocument: 'after', lean: true });
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
res.status(500);
|
|
169
|
+
res.json({ error: `there was a novel error` });
|
|
170
|
+
console.error(err);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!results) {
|
|
174
|
+
let sendable = await permissive_security_model.handle_empty_query_results(req, res, 'update');
|
|
175
|
+
res.json(sendable);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
res.json({ data: results });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
let post_path = [
|
|
182
|
+
api_prefix,
|
|
183
|
+
...base_layers_path_components,
|
|
184
|
+
`${collection.collection_id}`
|
|
185
|
+
].join('/');
|
|
186
|
+
app.post(post_path, async (req, res) => {
|
|
187
|
+
let permissive_security_model = await F_Security_Model.model_with_permission(access_layers.security_models, req, res, undefined, 'create');
|
|
188
|
+
if (!permissive_security_model) {
|
|
189
|
+
res.status(403);
|
|
190
|
+
res.json({ error: `You do not have permission to fetch documents from ${req.params.document_type}.` });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (collection.mongoose_schema.updated_by?.type === String) {
|
|
194
|
+
if (req.auth?.user_id) {
|
|
195
|
+
req.body.updated_by = req.auth?.user_id;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
req.body.updated_by = null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (collection.mongoose_schema.updated_at?.type === Date) {
|
|
202
|
+
req.body.updated_at = new Date();
|
|
203
|
+
}
|
|
204
|
+
if (collection.mongoose_schema.created_by?.type === String) {
|
|
205
|
+
if (req.auth?.user_id) {
|
|
206
|
+
req.body.created_by = req.auth?.user_id;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
req.body.created_by = null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (collection.mongoose_schema.created_at?.type === Date) {
|
|
213
|
+
req.body.created_at = new Date();
|
|
214
|
+
}
|
|
215
|
+
let validated_request_body;
|
|
216
|
+
try {
|
|
217
|
+
validated_request_body = await collection.post_validator.parse(req.body);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
if (err instanceof z.ZodError) {
|
|
221
|
+
res.status(400);
|
|
222
|
+
res.json({ error: err.issues });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.error(err);
|
|
227
|
+
res.status(500);
|
|
228
|
+
res.json({ error: `there was a novel error` });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (let layer of access_layers.layers) {
|
|
233
|
+
if (validated_request_body[`${layer}_id`] && validated_request_body[`${layer}_id`] !== req.params[layer]) {
|
|
234
|
+
res.status(403);
|
|
235
|
+
res.json({ error: `The system does not support changing the ${layer}_id of the document with this endpoint.` });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
let results;
|
|
240
|
+
try {
|
|
241
|
+
results = await collection.mongoose_model.create(validated_request_body);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
res.status(500);
|
|
245
|
+
res.json({ error: `there was a novel error` });
|
|
246
|
+
console.error(err);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!results) {
|
|
250
|
+
let sendable = await permissive_security_model.handle_empty_query_results(req, res, 'create');
|
|
251
|
+
res.json(sendable);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
res.json({ data: results });
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
let delete_path = [
|
|
258
|
+
api_prefix,
|
|
259
|
+
...base_layers_path_components,
|
|
260
|
+
`${collection.collection_id}/:document_id`
|
|
261
|
+
].join('/');
|
|
262
|
+
app.delete(delete_path, async (req, res) => {
|
|
263
|
+
if (!isValidObjectId(req.params.document_id)) {
|
|
264
|
+
res.status(400);
|
|
265
|
+
res.json({ error: `${req.params.document_id} is not a valid document ID.` });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
let find = { '_id': req.params.document_id };
|
|
269
|
+
for (let layer of access_layers.layers) {
|
|
270
|
+
find[`${layer}_id`] = req.params[layer];
|
|
271
|
+
}
|
|
272
|
+
let permissive_security_model = await F_Security_Model.model_with_permission(access_layers.security_models, req, res, find, 'delete');
|
|
273
|
+
if (!permissive_security_model) {
|
|
274
|
+
res.status(403);
|
|
275
|
+
res.json({ error: `You do not have permission to fetch documents from ${req.params.document_type}.` });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
let results;
|
|
279
|
+
try {
|
|
280
|
+
results = await collection.mongoose_model.findOneAndDelete(find, { lean: true });
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
res.status(500);
|
|
284
|
+
res.json({ error: `there was a novel error` });
|
|
285
|
+
console.error(err);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (!results) {
|
|
289
|
+
let sendable = await permissive_security_model.handle_empty_query_results(req, res, 'delete');
|
|
290
|
+
res.json(sendable);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
res.json({ data: results });
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=F_Compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"F_Compile.js","sourceRoot":"","sources":["../src/F_Compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAyB,MAAM,yCAAyC,CAAC;AAClG,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzH,MAAM,UAAU,OAAO,CAA8D,GAAW,EAAE,UAAkD,EAAE,UAAkB;IACpK,KAAI,IAAI,aAAa,IAAI,UAAU,CAAC,aAAa,EAAC,CAAC;QAO/C,IAAI,2BAA2B,GAAG,aAAa,CAAC,MA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G,EAAC,CAAC;gBACT,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC,CAAC;gBAC/C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO;YACX,CAAC;YAED,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,IAAI,QAAQ,GAAG,MAAM,yBAAyB,CAAC,0BAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;gBAC9F,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACJ,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAChC,CAAC;QAEL,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { Request, Response } from "express";
|
|
3
|
+
import { Empty_Query_Possibilities, F_Security_Model, Operation } from "./F_Security_Model.js";
|
|
4
|
+
import { F_Collection } from "../F_Collection.js";
|
|
5
|
+
export declare class F_SM_Open_Access<Collection_ID extends string, ZodSchema extends z.ZodObject> extends F_Security_Model<Collection_ID, ZodSchema> {
|
|
6
|
+
constructor(collection: F_Collection<Collection_ID, ZodSchema>);
|
|
7
|
+
has_permission(req: Request, res: Response, find: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}, operation: Operation): Promise<boolean>;
|
|
10
|
+
handle_empty_query_results(req: Request, res: Response, operation: Operation): Promise<Empty_Query_Possibilities>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { F_Security_Model } from "./F_Security_Model.js";
|
|
2
|
+
export class F_SM_Open_Access extends F_Security_Model {
|
|
3
|
+
constructor(collection) {
|
|
4
|
+
super(collection);
|
|
5
|
+
this.needs_auth_user = false;
|
|
6
|
+
}
|
|
7
|
+
async has_permission(req, res, find, operation) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
async handle_empty_query_results(req, res, operation) {
|
|
11
|
+
return { data: null };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=F_SM_Open_Access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"F_SM_Open_Access.js","sourceRoot":"","sources":["../../src/F_Security_Models/F_SM_Open_Access.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,gBAAgB,EAAa,MAAM,uBAAuB,CAAC;AAG/F,MAAM,OAAO,gBAA8E,SAAQ,gBAA0C;IAEzI,YAAY,UAAkD;QAC1D,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAY,EAAE,GAAa,EAAE,IAA0B,EAAE,SAAoB;QAC9F,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAC,GAAY,EAAE,GAAa,EAAE,SAAoB;QAC9E,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IACzB,CAAC;CAEJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { Request, Response } from "express";
|
|
3
|
+
import { F_Collection } from "../F_Collection.js";
|
|
4
|
+
import { Authenticated_Request, Empty_Query_Possibilities, F_Security_Model, Operation } from "./F_Security_Model.js";
|
|
5
|
+
export declare class F_SM_Ownership<Collection_ID extends string, ZodSchema extends z.ZodObject> extends F_Security_Model<Collection_ID, ZodSchema> {
|
|
6
|
+
user_id_field: string;
|
|
7
|
+
constructor(collection: F_Collection<Collection_ID, ZodSchema>, user_id_field?: string);
|
|
8
|
+
has_permission(req: Authenticated_Request, res: Response, find: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}, operation: Operation): Promise<boolean>;
|
|
11
|
+
handle_empty_query_results(req: Request, res: Response, operation: Operation): Promise<Empty_Query_Possibilities>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { F_Security_Model } from "./F_Security_Model.js";
|
|
2
|
+
export class F_SM_Ownership extends F_Security_Model {
|
|
3
|
+
user_id_field;
|
|
4
|
+
constructor(collection, user_id_field = 'user_id') {
|
|
5
|
+
super(collection);
|
|
6
|
+
this.needs_auth_user = true;
|
|
7
|
+
this.user_id_field = user_id_field;
|
|
8
|
+
}
|
|
9
|
+
async has_permission(req, res, find, operation) {
|
|
10
|
+
let user_id = '' + req.auth.user_id;
|
|
11
|
+
if (operation === 'get') {
|
|
12
|
+
if (req.params.document_id) {
|
|
13
|
+
find[this.user_id_field] = user_id;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (find[this.user_id_field] === user_id) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (operation === 'update') {
|
|
21
|
+
find[this.user_id_field] = user_id;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (operation === 'create') {
|
|
25
|
+
if (req.body[this.user_id_field] === user_id) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (operation === 'delete') {
|
|
30
|
+
find[this.user_id_field] = user_id;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
async handle_empty_query_results(req, res, operation) {
|
|
36
|
+
if (req.params.document_id) {
|
|
37
|
+
let document_result = await this.collection.mongoose_model.findById(req.params.document_id);
|
|
38
|
+
if (document_result) {
|
|
39
|
+
res.status(403);
|
|
40
|
+
return { error: `You do not have permission to ${operation} documents from ${req.params.document_type}.` };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { data: null };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# source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S,KAAK,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC;YACnC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAC,GAAY,EAAE,GAAa,EAAE,SAAoB;QAC9E,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACzB,IAAI,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAE5F,IAAI,eAAe,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,OAAO,EAAE,KAAK,EAAE,iCAAiC,SAAS,mBAAmB,GAAG,CAAC,MAAM,CAAC,aAAa,GAAG,EAAE,CAAC;YAC/G,CAAC;QACL,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { Request, Response } from "express";
|
|
3
|
+
import { F_Collection } from "../F_Collection.js";
|
|
4
|
+
import { Cache } from "../utils/cache.js";
|
|
5
|
+
import { Authenticated_Request, Empty_Query_Possibilities, F_Security_Model, Operation } from "./F_Security_Model.js";
|
|
6
|
+
export declare class F_SM_Role_Membership<Collection_ID extends string, ZodSchema extends z.ZodObject> extends F_Security_Model<Collection_ID, ZodSchema> {
|
|
7
|
+
user_id_field: string;
|
|
8
|
+
role_id_field: string;
|
|
9
|
+
layer_collection_id: string;
|
|
10
|
+
role_membership_collection: F_Collection<string, any>;
|
|
11
|
+
role_membership_cache: Cache<any>;
|
|
12
|
+
role_collection: F_Collection<string, any>;
|
|
13
|
+
role_cache: Cache<any>;
|
|
14
|
+
constructor(collection: F_Collection<Collection_ID, ZodSchema>, layer_collection: F_Collection<string, any>, role_membership_collection: F_Collection<string, any>, role_collection: F_Collection<string, any>, role_membership_cache?: Cache<any>, role_cache?: Cache<any>, user_id_field?: string, role_id_field?: string);
|
|
15
|
+
has_permission(req: Authenticated_Request, res: Response, find: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}, operation: Operation): Promise<boolean>;
|
|
18
|
+
handle_empty_query_results(req: Request, res: Response, operation: Operation): Promise<Empty_Query_Possibilities>;
|
|
19
|
+
}
|