@communecter/cocolight-api-client 1.0.51 → 1.0.55
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/dist/401.cocolight-api-client.browser.js +1 -0
- package/dist/401.cocolight-api-client.cjs +1 -0
- package/dist/401.cocolight-api-client.mjs.js +1 -0
- package/dist/588.cocolight-api-client.browser.js +1 -0
- package/dist/588.cocolight-api-client.cjs +1 -0
- package/dist/588.cocolight-api-client.mjs.js +1 -0
- package/dist/593.cocolight-api-client.browser.js +1 -0
- package/dist/593.cocolight-api-client.cjs +1 -0
- package/dist/593.cocolight-api-client.mjs.js +1 -0
- package/dist/839.cocolight-api-client.browser.js +1 -0
- package/dist/839.cocolight-api-client.cjs +1 -0
- package/dist/839.cocolight-api-client.mjs.js +1 -0
- package/dist/cocolight-api-client.browser.js +3 -3
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js.map +1 -1
- package/package.json +28 -10
- package/src/{Api.js → Api.ts} +99 -91
- package/src/{ApiClient.js → ApiClient.ts} +444 -240
- package/src/EJSONType.ts +103 -0
- package/src/api/{Badge.js → Badge.ts} +56 -45
- package/src/api/BaseEntity.ts +3897 -0
- package/src/api/Comment.ts +200 -0
- package/src/api/{EndpointApi.js → EndpointApi.ts} +365 -299
- package/src/api/{EndpointApi.types.d.ts → EndpointApi.types.ts} +166 -9
- package/src/api/EntityRegistry.ts +208 -0
- package/src/api/Event.ts +332 -0
- package/src/api/News.ts +331 -0
- package/src/api/{Organization.js → Organization.ts} +155 -119
- package/src/api/{Poi.js → Poi.ts} +68 -60
- package/src/api/{Project.js → Project.ts} +150 -127
- package/src/api/{User.js → User.ts} +321 -256
- package/src/api/UserApi.ts +148 -0
- package/src/api/serverDataType/Comment.ts +88 -0
- package/src/api/serverDataType/Event.ts +80 -0
- package/src/api/serverDataType/News.ts +138 -0
- package/src/api/serverDataType/Organization.ts +80 -0
- package/src/api/serverDataType/Project.ts +71 -0
- package/src/api/serverDataType/User.ts +103 -0
- package/src/api/serverDataType/common.ts +80 -0
- package/src/endpoints.module.ts +2621 -0
- package/src/error.ts +86 -0
- package/src/index.ts +86 -0
- package/src/mixin/UserMixin.ts +4 -0
- package/src/types/api-responses.ts +217 -0
- package/src/types/entities.ts +22 -0
- package/src/types/error-guards.ts +230 -0
- package/src/types/index.ts +39 -0
- package/src/types/payloads.ts +21 -0
- package/src/types/transforms.ts +110 -0
- package/src/utils/{FileOfflineStorageStrategy.node.js → FileOfflineStorageStrategy.node.ts} +15 -12
- package/src/utils/{FileStorageStrategy.node.js → FileStorageStrategy.node.ts} +17 -14
- package/src/utils/MultiServerFileStorageStrategy.node.ts +67 -0
- package/src/utils/MultiServerTokenStorageStrategy.ts +139 -0
- package/src/utils/{OfflineClientManager.js → OfflineClientManager.ts} +82 -86
- package/src/utils/OfflineQueueStorageStrategy.ts +47 -0
- package/src/utils/TokenStorage.ts +77 -0
- package/src/utils/compat.ts +12 -0
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.ts +35 -0
- package/src/utils/{createDefaultOfflineStrategy.js → createDefaultOfflineStrategy.ts} +8 -3
- package/src/utils/createDefaultTokenStorageStrategy.ts +33 -0
- package/src/utils/{reactive.js → reactive.ts} +49 -40
- package/src/utils/stream-utils.node.ts +12 -0
- package/types/Api.d.ts +87 -0
- package/types/Api.d.ts.map +1 -0
- package/types/ApiClient.d.ts +437 -0
- package/types/ApiClient.d.ts.map +1 -0
- package/types/EJSONType.d.ts +53 -0
- package/types/EJSONType.d.ts.map +1 -0
- package/types/api/Badge.d.ts +24 -0
- package/types/api/Badge.d.ts.map +1 -0
- package/types/api/BaseEntity.d.ts +1322 -0
- package/types/api/BaseEntity.d.ts.map +1 -0
- package/types/api/Comment.d.ts +36 -0
- package/types/api/EndpointApi.d.ts +985 -0
- package/types/api/EndpointApi.d.ts.map +1 -0
- package/types/api/EndpointApi.types.d.ts +4233 -0
- package/types/api/EntityRegistry.d.ts +24 -0
- package/types/api/EntityRegistry.d.ts.map +1 -0
- package/types/api/Event.d.ts +122 -0
- package/types/api/Event.d.ts.map +1 -0
- package/types/api/News.d.ts +77 -0
- package/types/api/News.d.ts.map +1 -0
- package/types/api/Organization.d.ts +203 -0
- package/types/api/Organization.d.ts.map +1 -0
- package/types/api/Poi.d.ts +54 -0
- package/types/api/Poi.d.ts.map +1 -0
- package/types/api/Project.d.ts +180 -0
- package/types/api/Project.d.ts.map +1 -0
- package/types/api/User.d.ts +332 -0
- package/types/api/User.d.ts.map +1 -0
- package/types/api/UserApi.d.ts +64 -0
- package/types/api/UserApi.d.ts.map +1 -0
- package/types/api/serverDataType/Comment.d.ts +83 -0
- package/types/api/serverDataType/Event.d.ts +67 -0
- package/types/api/serverDataType/News.d.ts +130 -0
- package/types/api/serverDataType/Organization.d.ts +65 -0
- package/types/api/serverDataType/Organization.d.ts.map +1 -0
- package/types/api/serverDataType/Project.d.ts +58 -0
- package/types/api/serverDataType/Project.d.ts.map +1 -0
- package/types/api/serverDataType/User.d.ts +86 -0
- package/types/api/serverDataType/User.d.ts.map +1 -0
- package/types/api/serverDataType/common.d.ts +71 -0
- package/types/api/serverDataType/common.d.ts.map +1 -0
- package/types/endpoints.module.d.ts +20559 -0
- package/types/endpoints.module.d.ts.map +1 -0
- package/types/error.d.ts +54 -0
- package/types/error.d.ts.map +1 -0
- package/types/index.d.ts +59 -0
- package/types/index.d.ts.map +1 -0
- package/types/mixin/UserMixin.d.ts +1 -0
- package/types/mixin/UserMixin.d.ts.map +1 -0
- package/types/types/api-responses.d.ts +190 -0
- package/types/types/api-responses.d.ts.map +1 -0
- package/types/types/entities.d.ts +17 -0
- package/types/types/entities.d.ts.map +1 -0
- package/types/types/error-guards.d.ts +99 -0
- package/types/types/error-guards.d.ts.map +1 -0
- package/types/types/index.d.ts +7 -0
- package/types/types/payloads.d.ts +17 -0
- package/types/types/payloads.d.ts.map +1 -0
- package/types/types/transforms.d.ts +79 -0
- package/types/types/transforms.d.ts.map +1 -0
- package/types/utils/FileOfflineStorageStrategy.node.d.ts +11 -0
- package/types/utils/FileOfflineStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/FileStorageStrategy.node.d.ts +14 -0
- package/types/utils/FileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts +17 -0
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerTokenStorageStrategy.d.ts +44 -0
- package/types/utils/MultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/OfflineClientManager.d.ts +58 -0
- package/types/utils/OfflineClientManager.d.ts.map +1 -0
- package/types/utils/OfflineQueueStorageStrategy.d.ts +16 -0
- package/types/utils/OfflineQueueStorageStrategy.d.ts.map +1 -0
- package/types/utils/TokenStorage.d.ts +26 -0
- package/types/utils/TokenStorage.d.ts.map +1 -0
- package/types/utils/compat.d.ts +4 -0
- package/types/utils/compat.d.ts.map +1 -0
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts +2 -0
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultOfflineStrategy.d.ts +2 -0
- package/types/utils/createDefaultOfflineStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultTokenStorageStrategy.d.ts +2 -0
- package/types/utils/createDefaultTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/reactive.d.ts +54 -0
- package/types/utils/reactive.d.ts.map +1 -0
- package/types/utils/stream-utils.node.d.ts +3 -0
- package/types/utils/stream-utils.node.d.ts.map +1 -0
- package/dist/123.cocolight-api-client.browser.js +0 -1
- package/dist/123.cocolight-api-client.cjs +0 -1
- package/dist/22.cocolight-api-client.mjs.js +0 -1
- package/dist/339.cocolight-api-client.mjs.js +0 -1
- package/dist/394.cocolight-api-client.browser.js +0 -1
- package/dist/394.cocolight-api-client.cjs +0 -1
- package/dist/405.cocolight-api-client.browser.js +0 -1
- package/dist/405.cocolight-api-client.cjs +0 -1
- package/dist/774.cocolight-api-client.mjs.js +0 -1
- package/dist/790.cocolight-api-client.mjs.js +0 -1
- package/dist/931.cocolight-api-client.browser.js +0 -1
- package/dist/931.cocolight-api-client.cjs +0 -1
- package/src/EJSONType.js +0 -53
- package/src/api/BaseEntity.js +0 -2828
- package/src/api/EntityRegistry.js +0 -152
- package/src/api/Event.js +0 -226
- package/src/api/News.js +0 -244
- package/src/api/UserApi.js +0 -81
- package/src/endpoints.module.js +0 -5
- package/src/error.js +0 -68
- package/src/index.js +0 -34
- package/src/mixin/UserMixin.js +0 -8
- package/src/utils/MultiServerFileStorageStrategy.node.js +0 -65
- package/src/utils/MultiServerTokenStorageStrategy.js +0 -131
- package/src/utils/OfflineQueueStorageStrategy.js +0 -51
- package/src/utils/TokenStorage.js +0 -93
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.js +0 -45
- package/src/utils/createDefaultTokenStorageStrategy.js +0 -43
- package/src/utils/stream-utils.node.js +0 -10
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Fichier généré automatiquement
|
|
2
|
+
// Types générés depuis endpoints-copie.json
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
4
|
+
|
|
1
5
|
export interface PersonRegisterData {
|
|
2
6
|
/**
|
|
3
7
|
* Nom complet de l'utilisateur
|
|
@@ -787,7 +791,7 @@ export interface GetCommentsData {
|
|
|
787
791
|
|
|
788
792
|
export interface AddCommentsData {
|
|
789
793
|
/**
|
|
790
|
-
* ID du commentaire parent (optionnel)
|
|
794
|
+
* ID du commentaire parent (optionnel) ou chaîne vide
|
|
791
795
|
*/
|
|
792
796
|
parentCommentId?: string;
|
|
793
797
|
/**
|
|
@@ -1155,14 +1159,12 @@ export interface GetProjectsNoAdminData {
|
|
|
1155
1159
|
*/
|
|
1156
1160
|
notSourceKey: true;
|
|
1157
1161
|
filters: {
|
|
1158
|
-
$or
|
|
1162
|
+
$or?: Record<string, unknown>;
|
|
1159
1163
|
/**
|
|
1160
1164
|
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
1161
1165
|
* via the `patternProperty` "^links\.contributors\.(?:[a-f0-9]{24}|@\w+)$".
|
|
1162
1166
|
*/
|
|
1163
|
-
[k: string]:
|
|
1164
|
-
$exists: true;
|
|
1165
|
-
};
|
|
1167
|
+
[k: string]: unknown;
|
|
1166
1168
|
};
|
|
1167
1169
|
/**
|
|
1168
1170
|
* Localité vide ou spécifique
|
|
@@ -1237,14 +1239,12 @@ export interface GetProjectsAdminData {
|
|
|
1237
1239
|
*/
|
|
1238
1240
|
notSourceKey: true;
|
|
1239
1241
|
filters: {
|
|
1240
|
-
$or
|
|
1242
|
+
$or?: Record<string, unknown>;
|
|
1241
1243
|
/**
|
|
1242
1244
|
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
1243
1245
|
* via the `patternProperty` "^links\.contributors\.(?:[a-f0-9]{24}|@(?:\{[^}]+\}|[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)?))$".
|
|
1244
1246
|
*/
|
|
1245
|
-
[k: string]:
|
|
1246
|
-
$exists: true;
|
|
1247
|
-
};
|
|
1247
|
+
[k: string]: unknown;
|
|
1248
1248
|
};
|
|
1249
1249
|
/**
|
|
1250
1250
|
* Localité vide ou spécifique
|
|
@@ -4450,3 +4450,160 @@ export interface GetGalleryData {
|
|
|
4450
4450
|
};
|
|
4451
4451
|
[k: string]: unknown;
|
|
4452
4452
|
}
|
|
4453
|
+
|
|
4454
|
+
|
|
4455
|
+
export interface GetAttendeesNoAdminData {
|
|
4456
|
+
/**
|
|
4457
|
+
* Nom ou terme recherché
|
|
4458
|
+
*/
|
|
4459
|
+
name?: string;
|
|
4460
|
+
/**
|
|
4461
|
+
* Types d'entités à inclure dans la recherche
|
|
4462
|
+
*/
|
|
4463
|
+
searchType: "citoyens"[];
|
|
4464
|
+
/**
|
|
4465
|
+
* Critère de recherche (actuellement vide)
|
|
4466
|
+
*/
|
|
4467
|
+
searchBy?: "ALL";
|
|
4468
|
+
/**
|
|
4469
|
+
* Index de départ global pour la pagination
|
|
4470
|
+
*/
|
|
4471
|
+
indexMin: number;
|
|
4472
|
+
/**
|
|
4473
|
+
* Index de fin global pour la pagination
|
|
4474
|
+
*/
|
|
4475
|
+
indexMax?: number;
|
|
4476
|
+
/**
|
|
4477
|
+
* Nombre d’éléments à récupérer (limite de pagination)
|
|
4478
|
+
*/
|
|
4479
|
+
indexStep: number;
|
|
4480
|
+
/**
|
|
4481
|
+
* Configuration des plages de résultats pour chaque type de recherche
|
|
4482
|
+
*/
|
|
4483
|
+
ranges?: {
|
|
4484
|
+
/**
|
|
4485
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
4486
|
+
* via the `patternProperty` "^[^\s]+$".
|
|
4487
|
+
*/
|
|
4488
|
+
[k: string]: {
|
|
4489
|
+
/**
|
|
4490
|
+
* Index de départ pour la pagination
|
|
4491
|
+
*/
|
|
4492
|
+
indexMin: number;
|
|
4493
|
+
/**
|
|
4494
|
+
* Index de fin pour la pagination
|
|
4495
|
+
*/
|
|
4496
|
+
indexMax: number;
|
|
4497
|
+
};
|
|
4498
|
+
};
|
|
4499
|
+
/**
|
|
4500
|
+
* Type initial de la recherche, vide par défaut
|
|
4501
|
+
*/
|
|
4502
|
+
initType: "";
|
|
4503
|
+
/**
|
|
4504
|
+
* Indique si les types doivent être comptés dans les résultats
|
|
4505
|
+
*/
|
|
4506
|
+
count: true;
|
|
4507
|
+
/**
|
|
4508
|
+
* Liste fixe des types à compter dans les résultats
|
|
4509
|
+
*/
|
|
4510
|
+
countType: "citoyens"[];
|
|
4511
|
+
/**
|
|
4512
|
+
* Flag pour ne pas filtrer sur une clé de source spécifique
|
|
4513
|
+
*/
|
|
4514
|
+
notSourceKey: true;
|
|
4515
|
+
filters: {
|
|
4516
|
+
[k: string]: unknown;
|
|
4517
|
+
};
|
|
4518
|
+
/**
|
|
4519
|
+
* Localité vide ou spécifique
|
|
4520
|
+
*/
|
|
4521
|
+
locality: "";
|
|
4522
|
+
/**
|
|
4523
|
+
* Indique si la recherche doit s'étendre au Fediverse (toujours désactivé)
|
|
4524
|
+
*/
|
|
4525
|
+
fediverse: false;
|
|
4526
|
+
[k: string]: unknown;
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
|
|
4530
|
+
export interface GetAttendeesAdminData {
|
|
4531
|
+
/**
|
|
4532
|
+
* Nom ou terme recherché
|
|
4533
|
+
*/
|
|
4534
|
+
name?: string;
|
|
4535
|
+
/**
|
|
4536
|
+
* Types d'entités à inclure dans la recherche
|
|
4537
|
+
*/
|
|
4538
|
+
searchType: "citoyens"[];
|
|
4539
|
+
/**
|
|
4540
|
+
* Critère de recherche (actuellement vide)
|
|
4541
|
+
*/
|
|
4542
|
+
searchBy?: "ALL";
|
|
4543
|
+
/**
|
|
4544
|
+
* Index de départ global pour la pagination
|
|
4545
|
+
*/
|
|
4546
|
+
indexMin: number;
|
|
4547
|
+
/**
|
|
4548
|
+
* Index de fin global pour la pagination
|
|
4549
|
+
*/
|
|
4550
|
+
indexMax?: number;
|
|
4551
|
+
/**
|
|
4552
|
+
* Nombre d’éléments à récupérer (limite de pagination)
|
|
4553
|
+
*/
|
|
4554
|
+
indexStep: number;
|
|
4555
|
+
/**
|
|
4556
|
+
* Configuration des plages de résultats pour chaque type de recherche
|
|
4557
|
+
*/
|
|
4558
|
+
ranges?: {
|
|
4559
|
+
/**
|
|
4560
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
4561
|
+
* via the `patternProperty` "^[^\s]+$".
|
|
4562
|
+
*/
|
|
4563
|
+
[k: string]: {
|
|
4564
|
+
/**
|
|
4565
|
+
* Index de départ pour la pagination
|
|
4566
|
+
*/
|
|
4567
|
+
indexMin: number;
|
|
4568
|
+
/**
|
|
4569
|
+
* Index de fin pour la pagination
|
|
4570
|
+
*/
|
|
4571
|
+
indexMax: number;
|
|
4572
|
+
};
|
|
4573
|
+
};
|
|
4574
|
+
/**
|
|
4575
|
+
* Type initial de la recherche, vide par défaut
|
|
4576
|
+
*/
|
|
4577
|
+
initType: "";
|
|
4578
|
+
/**
|
|
4579
|
+
* Indique si les types doivent être comptés dans les résultats
|
|
4580
|
+
*/
|
|
4581
|
+
count: true;
|
|
4582
|
+
/**
|
|
4583
|
+
* Liste fixe des types à compter dans les résultats
|
|
4584
|
+
*/
|
|
4585
|
+
countType: "citoyens"[];
|
|
4586
|
+
/**
|
|
4587
|
+
* Flag pour ne pas filtrer sur une clé de source spécifique
|
|
4588
|
+
*/
|
|
4589
|
+
notSourceKey: true;
|
|
4590
|
+
filters: {
|
|
4591
|
+
[k: string]: unknown;
|
|
4592
|
+
};
|
|
4593
|
+
/**
|
|
4594
|
+
* Localité vide ou spécifique
|
|
4595
|
+
*/
|
|
4596
|
+
locality: "";
|
|
4597
|
+
/**
|
|
4598
|
+
* Indique si la recherche doit s'étendre au Fediverse (toujours désactivé)
|
|
4599
|
+
*/
|
|
4600
|
+
fediverse: false;
|
|
4601
|
+
pathParams?: {
|
|
4602
|
+
/**
|
|
4603
|
+
* ID du projet
|
|
4604
|
+
*/
|
|
4605
|
+
id: string;
|
|
4606
|
+
[k: string]: unknown;
|
|
4607
|
+
};
|
|
4608
|
+
[k: string]: unknown;
|
|
4609
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// TypeScript native types
|
|
2
|
+
import type { CollectionType } from "../types/entities.js";
|
|
3
|
+
|
|
4
|
+
export type EntityTag = "User" | "Organization" | "Project" | "Event" | "Poi" | "Badge" | "News" | "Comment";
|
|
5
|
+
export type CollectionKey = CollectionType; // Alias pour compatibilité
|
|
6
|
+
type BaseEntity = import("./BaseEntity.js").BaseEntity<any>;
|
|
7
|
+
type ApiClient = import("../ApiClient.js").default;
|
|
8
|
+
|
|
9
|
+
type EndpointApiClass = typeof import("./EndpointApi.js").default;
|
|
10
|
+
type EntityConstructor = new (...args: any[]) => BaseEntity;
|
|
11
|
+
type EntityClass = EntityConstructor & {
|
|
12
|
+
fromJSON?: (json: unknown, parent?: ApiClient | BaseEntity | null, deps?: EntityDeps) => BaseEntity;
|
|
13
|
+
};
|
|
14
|
+
type EntityDeps = Partial<Record<EntityTag | "EndpointApi", EntityClass | EndpointApiClass | undefined>>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Métadonnées de construction d'entité.
|
|
18
|
+
*/
|
|
19
|
+
type EntityMeta = {
|
|
20
|
+
entityClass: EntityClass;
|
|
21
|
+
deps: EntityDeps;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Types minimaux pour le JSON d'entité
|
|
26
|
+
*/
|
|
27
|
+
type MinimalEntityJSON = {
|
|
28
|
+
__entityTag: EntityTag;
|
|
29
|
+
serverData?: {
|
|
30
|
+
collection?: CollectionKey;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const EntityRegistry: Map<EntityTag | "EndpointApi", EntityClass | EndpointApiClass> = new Map();
|
|
35
|
+
|
|
36
|
+
// Overloads for registerEntity
|
|
37
|
+
export function registerEntity(tag: "EndpointApi", EntityClass: EndpointApiClass): void;
|
|
38
|
+
export function registerEntity(tag: EntityTag, EntityClass: EntityClass): void;
|
|
39
|
+
export function registerEntity(tag: EntityTag | "EndpointApi", EntityClass: EntityClass | EndpointApiClass): void {
|
|
40
|
+
EntityRegistry.set(tag, EntityClass);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Type guard: vérifie si la valeur ressemble à un JSON d'entité.
|
|
46
|
+
*/
|
|
47
|
+
function isEntityJSON(v: unknown): v is MinimalEntityJSON {
|
|
48
|
+
return !!v && typeof v === "object"
|
|
49
|
+
&& "__entityTag" in (v as any);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Récupère une instance depuis un JSON générique.
|
|
54
|
+
* Si la collection ou la métadonnée d'entité est absente, renvoie l'objet d'origine.
|
|
55
|
+
*/
|
|
56
|
+
export function fromEntityJSON(json: unknown, parent: ApiClient | BaseEntity | null = null): BaseEntity | unknown | null {
|
|
57
|
+
// On gère null / non-objet / pas une entité → on renvoie tel quel (ou null si tu préfères)
|
|
58
|
+
if (!isEntityJSON(json)) return json;
|
|
59
|
+
|
|
60
|
+
// Ici, TS sait que json.__entityTag existe
|
|
61
|
+
if (!json.serverData?.collection) return json;
|
|
62
|
+
|
|
63
|
+
const meta = _getEntityMeta(json.serverData.collection, json.__entityTag);
|
|
64
|
+
if (!meta) return json;
|
|
65
|
+
|
|
66
|
+
if (!meta.entityClass?.fromJSON) {
|
|
67
|
+
throw new Error(`Classe inconnue ou fromJSON manquant pour ${json.__entityTag}`);
|
|
68
|
+
}
|
|
69
|
+
return meta.entityClass.fromJSON(json, parent, meta.deps);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Récupère la classe d'entité et ses dépendances à partir du type d'entité.
|
|
74
|
+
*/
|
|
75
|
+
function _getEntityMeta(entityType: CollectionKey, __entityTag: EntityTag): EntityMeta | null {
|
|
76
|
+
const selfClass = EntityRegistry.get(__entityTag);
|
|
77
|
+
const selfTag = __entityTag;
|
|
78
|
+
|
|
79
|
+
console.log("=== _getEntityMeta DEBUG ===");
|
|
80
|
+
console.log("entityType:", entityType);
|
|
81
|
+
console.log("__entityTag:", __entityTag);
|
|
82
|
+
console.log("EntityRegistry.get('Comment'):", EntityRegistry.get("Comment"));
|
|
83
|
+
|
|
84
|
+
const commonDeps: EntityDeps = {
|
|
85
|
+
EndpointApi: EntityRegistry.get("EndpointApi"),
|
|
86
|
+
User: selfTag === "User" ? selfClass : EntityRegistry.get("User"),
|
|
87
|
+
Organization: selfTag === "Organization" ? selfClass : EntityRegistry.get("Organization"),
|
|
88
|
+
Project: selfTag === "Project" ? selfClass : EntityRegistry.get("Project"),
|
|
89
|
+
Event: selfTag === "Event" ? selfClass : EntityRegistry.get("Event"),
|
|
90
|
+
Poi: selfTag === "Poi" ? selfClass : EntityRegistry.get("Poi"),
|
|
91
|
+
Badge: selfTag === "Badge" ? selfClass : EntityRegistry.get("Badge"),
|
|
92
|
+
News: selfTag === "News" ? selfClass : EntityRegistry.get("News"),
|
|
93
|
+
Comment: selfTag === "Comment" ? selfClass : EntityRegistry.get("Comment"),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const map: Record<CollectionKey, EntityMeta> = {
|
|
97
|
+
citoyens: { entityClass: commonDeps.User as EntityClass, deps: commonDeps },
|
|
98
|
+
organizations:{ entityClass: commonDeps.Organization as EntityClass, deps: commonDeps },
|
|
99
|
+
projects: { entityClass: commonDeps.Project as EntityClass, deps: commonDeps },
|
|
100
|
+
events: { entityClass: commonDeps.Event as EntityClass, deps: { ...commonDeps, Badge: undefined } },
|
|
101
|
+
poi: { entityClass: commonDeps.Poi as EntityClass, deps: { ...commonDeps, Badge: undefined, News: undefined } },
|
|
102
|
+
news: { entityClass: commonDeps.News as EntityClass, deps: { ...commonDeps } },
|
|
103
|
+
badges: { entityClass: commonDeps.Badge as EntityClass, deps: {
|
|
104
|
+
EndpointApi: commonDeps.EndpointApi,
|
|
105
|
+
User: commonDeps.User,
|
|
106
|
+
Organization: commonDeps.Organization,
|
|
107
|
+
Project: commonDeps.Project
|
|
108
|
+
} },
|
|
109
|
+
comments: { entityClass: commonDeps.Comment as EntityClass, deps: { ...commonDeps } }
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return map[entityType] || null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type CollectionMapEntry = {
|
|
116
|
+
entityTag: EntityTag;
|
|
117
|
+
meta: (tag: EntityTag) => EntityMeta;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Crée une instance d'entité basée sur le seul nom de la collection.
|
|
122
|
+
*/
|
|
123
|
+
export function createFromCollection(collection: CollectionKey, parent: ApiClient | BaseEntity | null = null, data: object = {}): BaseEntity | null {
|
|
124
|
+
const _collectionMap: Record<CollectionKey, CollectionMapEntry> = {
|
|
125
|
+
citoyens: {
|
|
126
|
+
entityTag: "User",
|
|
127
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
128
|
+
},
|
|
129
|
+
organizations: {
|
|
130
|
+
entityTag: "Organization",
|
|
131
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
132
|
+
},
|
|
133
|
+
projects: {
|
|
134
|
+
entityTag: "Project",
|
|
135
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
136
|
+
},
|
|
137
|
+
events: {
|
|
138
|
+
entityTag: "Event",
|
|
139
|
+
meta: tag => _buildMeta(tag, { remove: ["Badge"] })
|
|
140
|
+
},
|
|
141
|
+
poi: {
|
|
142
|
+
entityTag: "Poi",
|
|
143
|
+
meta: tag => _buildMeta(tag, { remove: ["Badge","News"] })
|
|
144
|
+
},
|
|
145
|
+
news: {
|
|
146
|
+
entityTag: "News",
|
|
147
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
148
|
+
},
|
|
149
|
+
badges: {
|
|
150
|
+
entityTag: "Badge",
|
|
151
|
+
meta: () => _buildCustomMeta("Badge")
|
|
152
|
+
},
|
|
153
|
+
comments: {
|
|
154
|
+
entityTag: "Comment",
|
|
155
|
+
meta: tag => _buildMeta(tag, { remove: [] })
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const entry = _collectionMap[collection];
|
|
159
|
+
if (!entry) {
|
|
160
|
+
console.warn(`Collection inconnue : '${collection}'`);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const { entityTag, meta } = entry;
|
|
164
|
+
const { entityClass, deps } = meta(entityTag);
|
|
165
|
+
if (!entityClass) {
|
|
166
|
+
throw new Error(`EntityClass introuvable pour ${entityTag}`);
|
|
167
|
+
}
|
|
168
|
+
const Ctor = entityClass as EntityConstructor;
|
|
169
|
+
return new Ctor(parent, data, deps);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Construit entityClass et deps pour une collection standard.
|
|
174
|
+
*/
|
|
175
|
+
function _buildMeta(tag: EntityTag, options: { remove: string[] }): EntityMeta {
|
|
176
|
+
const EntityClass = EntityRegistry.get(tag) as EntityClass;
|
|
177
|
+
const allDeps: EntityDeps = {
|
|
178
|
+
EndpointApi: EntityRegistry.get("EndpointApi"),
|
|
179
|
+
User: EntityRegistry.get("User"),
|
|
180
|
+
Organization: EntityRegistry.get("Organization"),
|
|
181
|
+
Project: EntityRegistry.get("Project"),
|
|
182
|
+
Event: EntityRegistry.get("Event"),
|
|
183
|
+
Poi: EntityRegistry.get("Poi"),
|
|
184
|
+
Badge: EntityRegistry.get("Badge"),
|
|
185
|
+
News: EntityRegistry.get("News"),
|
|
186
|
+
Comment: EntityRegistry.get("Comment"),
|
|
187
|
+
};
|
|
188
|
+
// inject self
|
|
189
|
+
(allDeps as any)[tag] = EntityClass;
|
|
190
|
+
// remove undesired
|
|
191
|
+
options.remove.forEach(dep => delete (allDeps as any)[dep]);
|
|
192
|
+
return { entityClass: EntityClass, deps: allDeps };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Cas spécifique des badges : seules certaines dépendances.
|
|
197
|
+
*/
|
|
198
|
+
function _buildCustomMeta(tag: "Badge"): EntityMeta {
|
|
199
|
+
const EntityClass = EntityRegistry.get(tag) as EntityClass;
|
|
200
|
+
const deps: EntityDeps = {
|
|
201
|
+
EndpointApi: EntityRegistry.get("EndpointApi"),
|
|
202
|
+
User: EntityRegistry.get("User"),
|
|
203
|
+
Organization: EntityRegistry.get("Organization"),
|
|
204
|
+
Project: EntityRegistry.get("Project")
|
|
205
|
+
};
|
|
206
|
+
(deps as any)[tag] = EntityClass;
|
|
207
|
+
return { entityClass: EntityClass, deps };
|
|
208
|
+
}
|