@api-client/core 0.11.11 → 0.12.1
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/Testing.md +1 -1
- package/bin/plugins/events/EventPlugin.ts +61 -0
- package/bin/plugins/events/assert.ts +193 -0
- package/bin/plugins/events/types.ts +6 -0
- package/bin/test.ts +8 -1
- package/build/src/amf/AmfShapeGenerator.d.ts +6 -3
- package/build/src/amf/AmfShapeGenerator.d.ts.map +1 -1
- package/build/src/amf/AmfShapeGenerator.js +7 -4
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/AmfTypes.d.ts +2 -2
- package/build/src/amf/AmfTypes.d.ts.map +1 -1
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/DataValueGenerator.d.ts +15 -15
- package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
- package/build/src/amf/DataValueGenerator.js +17 -16
- package/build/src/amf/DataValueGenerator.js.map +1 -1
- package/build/src/amf/models/AmfDataNode.d.ts.map +1 -1
- package/build/src/amf/models/AmfDataNode.js +2 -2
- package/build/src/amf/models/AmfDataNode.js.map +1 -1
- package/build/src/browser.d.ts +12 -9
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +11 -8
- package/build/src/browser.js.map +1 -1
- package/build/src/exceptions/attach_exception.d.ts +11 -0
- package/build/src/exceptions/attach_exception.d.ts.map +1 -0
- package/build/src/exceptions/attach_exception.js +11 -0
- package/build/src/exceptions/attach_exception.js.map +1 -0
- package/build/src/exceptions/detach_exception.d.ts +11 -0
- package/build/src/exceptions/detach_exception.d.ts.map +1 -0
- package/build/src/exceptions/detach_exception.js +11 -0
- package/build/src/exceptions/detach_exception.js.map +1 -0
- package/build/src/exceptions/remove_model_exception.d.ts +8 -0
- package/build/src/exceptions/remove_model_exception.d.ts.map +1 -0
- package/build/src/exceptions/remove_model_exception.js +8 -0
- package/build/src/exceptions/remove_model_exception.js.map +1 -0
- package/build/src/exceptions/remove_namespace_exception.d.ts +8 -0
- package/build/src/exceptions/remove_namespace_exception.d.ts.map +1 -0
- package/build/src/exceptions/remove_namespace_exception.js +8 -0
- package/build/src/exceptions/remove_namespace_exception.js.map +1 -0
- package/build/src/index.d.ts +12 -9
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +11 -8
- package/build/src/index.js.map +1 -1
- package/build/src/legacy.d.ts +8 -0
- package/build/src/legacy.d.ts.map +1 -1
- package/build/src/legacy.js +9 -0
- package/build/src/legacy.js.map +1 -1
- package/build/src/lib/uuid.d.ts +1 -1
- package/build/src/lib/uuid.js +1 -1
- package/build/src/lib/uuid.js.map +1 -1
- package/build/src/mocking/lib/History.js +8 -8
- package/build/src/mocking/lib/History.js.map +1 -1
- package/build/src/mocking/lib/HostRules.js +1 -1
- package/build/src/mocking/lib/HostRules.js.map +1 -1
- package/build/src/mocking/lib/User.js +2 -2
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/modeling/Bindings.d.ts +2 -2
- package/build/src/modeling/Bindings.d.ts.map +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +601 -0
- package/build/src/modeling/DataDomain.d.ts.map +1 -0
- package/build/src/modeling/DataDomain.js +1141 -0
- package/build/src/modeling/DataDomain.js.map +1 -0
- package/build/src/modeling/DataFormat.d.ts +42 -41
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +30 -131
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +281 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -0
- package/build/src/modeling/DomainAssociation.js +440 -0
- package/build/src/modeling/DomainAssociation.js.map +1 -0
- package/build/src/modeling/DomainElement.d.ts +33 -0
- package/build/src/modeling/DomainElement.d.ts.map +1 -0
- package/build/src/modeling/DomainElement.js +32 -0
- package/build/src/modeling/DomainElement.js.map +1 -0
- package/build/src/modeling/DomainEntity.d.ts +383 -0
- package/build/src/modeling/DomainEntity.d.ts.map +1 -0
- package/build/src/modeling/DomainEntity.js +718 -0
- package/build/src/modeling/DomainEntity.js.map +1 -0
- package/build/src/modeling/DomainFile.d.ts +25 -0
- package/build/src/modeling/DomainFile.d.ts.map +1 -0
- package/build/src/modeling/DomainFile.js +86 -0
- package/build/src/modeling/DomainFile.js.map +1 -0
- package/build/src/modeling/DomainImpactAnalysis.d.ts +60 -47
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +201 -132
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +226 -0
- package/build/src/modeling/DomainModel.d.ts.map +1 -0
- package/build/src/modeling/DomainModel.js +401 -0
- package/build/src/modeling/DomainModel.js.map +1 -0
- package/build/src/modeling/DomainNamespace.d.ts +268 -0
- package/build/src/modeling/DomainNamespace.d.ts.map +1 -0
- package/build/src/modeling/DomainNamespace.js +512 -0
- package/build/src/modeling/DomainNamespace.js.map +1 -0
- package/build/src/modeling/DomainProperty.d.ts +281 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -0
- package/build/src/modeling/DomainProperty.js +560 -0
- package/build/src/modeling/DomainProperty.js.map +1 -0
- package/build/src/modeling/DomainSerialization.d.ts +40 -0
- package/build/src/modeling/DomainSerialization.d.ts.map +1 -0
- package/build/src/modeling/DomainSerialization.js +288 -0
- package/build/src/modeling/DomainSerialization.js.map +1 -0
- package/build/src/modeling/DomainVersioning.d.ts +17 -0
- package/build/src/modeling/DomainVersioning.d.ts.map +1 -0
- package/build/src/modeling/DomainVersioning.js +124 -0
- package/build/src/modeling/DomainVersioning.js.map +1 -0
- package/build/src/modeling/GraphUtils.d.ts +8 -0
- package/build/src/modeling/GraphUtils.d.ts.map +1 -0
- package/build/src/modeling/GraphUtils.js +26 -0
- package/build/src/modeling/GraphUtils.js.map +1 -0
- package/build/src/modeling/amf/ShapeGenerator.d.ts +164 -0
- package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -0
- package/build/src/modeling/amf/ShapeGenerator.js +492 -0
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -0
- package/build/src/modeling/{DataAssociation.d.ts → legacy/DataAssociation.d.ts} +10 -5
- package/build/src/modeling/legacy/DataAssociation.d.ts.map +1 -0
- package/build/src/modeling/{DataAssociation.js → legacy/DataAssociation.js} +11 -8
- package/build/src/modeling/legacy/DataAssociation.js.map +1 -0
- package/build/src/modeling/{DataEntity.d.ts → legacy/DataEntity.d.ts} +12 -7
- package/build/src/modeling/legacy/DataEntity.d.ts.map +1 -0
- package/build/src/modeling/{DataEntity.js → legacy/DataEntity.js} +21 -20
- package/build/src/modeling/legacy/DataEntity.js.map +1 -0
- package/build/src/modeling/{DataEntityBuilder.d.ts → legacy/DataEntityBuilder.d.ts} +3 -2
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +1 -0
- package/build/src/modeling/{DataEntityBuilder.js → legacy/DataEntityBuilder.js} +4 -3
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +298 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +1 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.js +441 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.js.map +1 -0
- package/build/src/modeling/{DataModel.d.ts → legacy/DataModel.d.ts} +6 -4
- package/build/src/modeling/legacy/DataModel.d.ts.map +1 -0
- package/build/src/modeling/{DataModel.js → legacy/DataModel.js} +9 -8
- package/build/src/modeling/legacy/DataModel.js.map +1 -0
- package/build/src/modeling/{DataNamespace.d.ts → legacy/DataNamespace.d.ts} +22 -3
- package/build/src/modeling/legacy/DataNamespace.d.ts.map +1 -0
- package/build/src/modeling/{DataNamespace.js → legacy/DataNamespace.js} +9 -5
- package/build/src/modeling/legacy/DataNamespace.js.map +1 -0
- package/build/src/modeling/{DataProperty.d.ts → legacy/DataProperty.d.ts} +13 -5
- package/build/src/modeling/legacy/DataProperty.d.ts.map +1 -0
- package/build/src/modeling/{DataProperty.js → legacy/DataProperty.js} +10 -7
- package/build/src/modeling/legacy/DataProperty.js.map +1 -0
- package/build/src/modeling/observed.d.ts +67 -0
- package/build/src/modeling/observed.d.ts.map +1 -0
- package/build/src/modeling/observed.js +230 -0
- package/build/src/modeling/observed.js.map +1 -0
- package/build/src/modeling/types.d.ts +165 -1
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/AuthorizationData.js +3 -3
- package/build/src/models/AuthorizationData.js.map +1 -1
- package/build/src/models/CertificateFile.js +2 -2
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/ClientCertificate.js +5 -5
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.js +6 -6
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Folder.js +2 -2
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/HostRule.js +4 -4
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpProject.js +12 -12
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/Project.d.ts.map +1 -1
- package/build/src/models/Project.js +2 -2
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts.map +1 -1
- package/build/src/models/ProjectFolder.js +6 -6
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts.map +1 -1
- package/build/src/models/ProjectRequest.js +8 -8
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.js +6 -6
- package/build/src/models/ProjectSchema.js.map +1 -1
- package/build/src/models/Thing.d.ts +26 -5
- package/build/src/models/Thing.d.ts.map +1 -1
- package/build/src/models/Thing.js +193 -91
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/kinds.d.ts +31 -6
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +31 -6
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/DataFile.d.ts +3 -1
- package/build/src/models/store/DataFile.d.ts.map +1 -1
- package/build/src/models/store/DataFile.js +4 -2
- package/build/src/models/store/DataFile.js.map +1 -1
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +3 -3
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Organization.js +3 -3
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/models/store/Permission.js +7 -7
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/store/UserIdentity.js +3 -3
- package/build/src/models/store/UserIdentity.js.map +1 -1
- package/build/src/models/transformers/ArcDexieTransformer.js +4 -4
- package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js +3 -3
- package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcPouchTransformer.js +2 -2
- package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/models/types.d.ts +12 -0
- package/build/src/models/types.d.ts.map +1 -0
- package/build/src/models/types.js +2 -0
- package/build/src/models/types.js.map +1 -0
- package/build/src/patch/PatchClient.js +2 -2
- package/build/src/patch/PatchClient.js.map +1 -1
- package/build/src/runtime/store/FilesSdk.d.ts +2 -2
- package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
- package/build/src/runtime/store/FilesSdk.js +3 -3
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/data/models/example-generator-api.json +8 -8
- package/package.json +20 -6
- package/readme.md +1 -1
- package/src/amf/AmfShapeGenerator.ts +10 -7
- package/src/amf/AmfTypes.ts +2 -2
- package/src/amf/DataValueGenerator.ts +24 -23
- package/src/amf/models/AmfDataNode.ts +2 -2
- package/src/exceptions/attach_exception.ts +11 -0
- package/src/exceptions/detach_exception.ts +11 -0
- package/src/exceptions/remove_model_exception.ts +8 -0
- package/src/exceptions/remove_namespace_exception.ts +8 -0
- package/src/lib/uuid.ts +1 -1
- package/src/mocking/lib/History.ts +8 -8
- package/src/mocking/lib/HostRules.ts +1 -1
- package/src/mocking/lib/User.ts +2 -2
- package/src/modeling/Bindings.ts +2 -2
- package/src/modeling/DataDomain.ts +1220 -0
- package/src/modeling/DataFormat.ts +54 -163
- package/src/modeling/DomainAssociation.ts +476 -0
- package/src/modeling/DomainElement.ts +50 -0
- package/src/modeling/DomainEntity.ts +769 -0
- package/src/modeling/DomainFile.ts +94 -0
- package/src/modeling/DomainImpactAnalysis.ts +218 -144
- package/src/modeling/DomainModel.ts +421 -0
- package/src/modeling/DomainNamespace.ts +537 -0
- package/src/modeling/DomainProperty.ts +548 -0
- package/src/modeling/DomainSerialization.ts +312 -0
- package/src/modeling/DomainVersioning.ts +144 -0
- package/src/modeling/GraphUtils.ts +28 -0
- package/src/modeling/amf/ShapeGenerator.ts +552 -0
- package/src/modeling/graph.md +115 -0
- package/src/modeling/{DataAssociation.ts → legacy/DataAssociation.ts} +15 -10
- package/src/modeling/{DataEntity.ts → legacy/DataEntity.ts} +30 -25
- package/src/modeling/{DataEntityBuilder.ts → legacy/DataEntityBuilder.ts} +5 -4
- package/src/modeling/legacy/DataImpactAnalysis.ts +530 -0
- package/src/modeling/{DataModel.ts → legacy/DataModel.ts} +12 -10
- package/src/modeling/{DataNamespace.ts → legacy/DataNamespace.ts} +25 -7
- package/src/modeling/{DataProperty.ts → legacy/DataProperty.ts} +17 -9
- package/src/modeling/observed.ts +267 -0
- package/src/modeling/types.ts +174 -1
- package/src/models/AuthorizationData.ts +3 -3
- package/src/models/CertificateFile.ts +2 -2
- package/src/models/ClientCertificate.ts +5 -5
- package/src/models/Environment.ts +6 -6
- package/src/models/Folder.ts +2 -2
- package/src/models/HostRule.ts +4 -4
- package/src/models/HttpProject.ts +12 -12
- package/src/models/Project.ts +2 -2
- package/src/models/ProjectFolder.ts +6 -6
- package/src/models/ProjectRequest.ts +8 -8
- package/src/models/ProjectSchema.ts +6 -6
- package/src/models/Thing.ts +70 -5
- package/src/models/kinds.ts +32 -6
- package/src/models/store/DataFile.ts +5 -3
- package/src/models/store/File.ts +3 -3
- package/src/models/store/Organization.ts +3 -3
- package/src/models/store/Permission.ts +7 -7
- package/src/models/store/UserIdentity.ts +3 -3
- package/src/models/transformers/ArcDexieTransformer.ts +4 -4
- package/src/models/transformers/ArcLegacyTransformer.ts +3 -3
- package/src/models/transformers/ArcPouchTransformer.ts +2 -2
- package/src/models/transformers/PostmanV21Transformer.ts +2 -2
- package/src/models/transformers/PostmanV2Transformer.ts +2 -2
- package/src/models/types.ts +11 -0
- package/src/patch/PatchClient.ts +2 -2
- package/src/runtime/store/FilesSdk.ts +5 -5
- package/tests/unit/amf/data_value_generator.spec.ts +15 -15
- package/tests/unit/legacy-transformers/ARC-legacy-import.spec.ts +1 -1
- package/tests/unit/modeling/amf/shape_generator.spec.ts +1174 -0
- package/tests/unit/modeling/data_domain.spec.ts +444 -0
- package/tests/unit/modeling/data_domain_associations.spec.ts +279 -0
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +681 -0
- package/tests/unit/modeling/data_domain_entities.spec.ts +449 -0
- package/tests/unit/modeling/data_domain_foreign.spec.ts +355 -0
- package/tests/unit/modeling/data_domain_models.spec.ts +658 -0
- package/tests/unit/modeling/data_domain_namespaces.spec.ts +668 -0
- package/tests/unit/modeling/data_domain_property.spec.ts +264 -0
- package/tests/unit/modeling/data_domain_serialization.spec.ts +294 -0
- package/tests/unit/modeling/domain.property.spec.ts +822 -0
- package/tests/unit/modeling/domain_asociation.spec.ts +643 -0
- package/tests/unit/modeling/domain_asociation_targets.spec.ts +350 -0
- package/tests/unit/modeling/domain_entity.spec.ts +730 -0
- package/tests/unit/modeling/domain_entity_associations.spec.ts +330 -0
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +988 -0
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +1451 -0
- package/tests/unit/modeling/domain_entity_fields.spec.ts +113 -0
- package/tests/unit/modeling/domain_entity_generators.spec.ts +20 -0
- package/tests/unit/modeling/domain_entity_parents.spec.ts +291 -0
- package/tests/unit/modeling/domain_entity_properties.spec.ts +305 -0
- package/tests/unit/modeling/{data_file.spec.ts → domain_file.spec.ts} +29 -85
- package/tests/unit/modeling/domain_impact_analysis.spec.ts +452 -0
- package/tests/unit/modeling/domain_model.spec.ts +568 -0
- package/tests/unit/modeling/domain_model_entities.spec.ts +408 -0
- package/tests/unit/modeling/domain_namespace.spec.ts +514 -0
- package/tests/unit/modeling/domain_namespace_models.spec.ts +324 -0
- package/tests/unit/modeling/domain_namespace_namespaces.spec.ts +404 -0
- package/tests/unit/modeling/domain_versioning.spec.ts +140 -0
- package/tests/unit/{amf → modeling/legacy}/amf_shape_generator.spec.ts +11 -11
- package/tests/unit/modeling/{data_association.spec.ts → legacy/data_association.spec.ts} +3 -11
- package/tests/unit/modeling/{data_entity.spec.ts → legacy/data_entity.spec.ts} +10 -8
- package/tests/unit/modeling/{data_entity_generator_json.spec.ts → legacy/data_entity_generator_json.spec.ts} +1 -1
- package/tests/unit/modeling/{data_entity_generator_xml.spec.ts → legacy/data_entity_generator_xml.spec.ts} +1 -1
- package/tests/unit/modeling/{data_model.spec.ts → legacy/data_model.spec.ts} +3 -3
- package/tests/unit/modeling/{data_namespace.spec.ts → legacy/data_namespace.spec.ts} +3 -10
- package/tests/unit/modeling/{data_property.spec.ts → legacy/data_property.spec.ts} +3 -6
- package/tests/unit/modeling/{impact_analysis.spec.ts → legacy/impact_analysis.spec.ts} +9 -9
- package/tests/unit/models/File/new.spec.ts +1 -1
- package/tests/unit/models/HttpProject.spec.ts +3 -3
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +8 -8
- package/tsconfig.node.json +35 -0
- package/build/src/modeling/DataAssociation.d.ts.map +0 -1
- package/build/src/modeling/DataAssociation.js.map +0 -1
- package/build/src/modeling/DataEntity.d.ts.map +0 -1
- package/build/src/modeling/DataEntity.js.map +0 -1
- package/build/src/modeling/DataEntityBuilder.d.ts.map +0 -1
- package/build/src/modeling/DataEntityBuilder.js.map +0 -1
- package/build/src/modeling/DataModel.d.ts.map +0 -1
- package/build/src/modeling/DataModel.js.map +0 -1
- package/build/src/modeling/DataNamespace.d.ts.map +0 -1
- package/build/src/modeling/DataNamespace.js.map +0 -1
- package/build/src/modeling/DataProperty.d.ts.map +0 -1
- package/build/src/modeling/DataProperty.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAkB,MAAM,iBAAiB,CAAA;AAGzE,OAAO,EAAS,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAwIxC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAC/C,MAAM,mBAAmB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AACnD,MAAM,o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AAC,iBAAiB,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { IPermission, Permission, PermissionRole } from './Permission.js'\nimport { IModification } from './Modification.js'\nimport { IDeletion } from './Deletion.js'\nimport { IUser, Kind as UserKind } from './User.js'\nimport { IThing, Thing } from '../Thing.js'\nimport v4 from '../../lib/uuid.js'\nimport { ICapabilities } from './Capabilities.js'\nimport { FolderKind } from '../kinds.js'\n// this causes error\n// import { Kind as FolderKind } from '../Folder.js';\n\nexport interface FileAddOptions {\n /**\n * The parent folder where to put the file.\n * The `parents` array is always cleared from the file object before adding it to the store.\n */\n parent?: string\n}\n\nexport interface MediaReadOptions {\n /**\n * When set it reads the file that was marked as `_deleted`. By default it throws when file was deleted.\n */\n deleted?: boolean\n}\n\n/**\n * A breadcrumb when creating the breadcrumb list for a file.\n */\nexport interface FileBreadcrumb {\n /**\n * The datastore key of the object.\n */\n key: string\n /**\n * THe kind of the object.\n */\n kind: string\n /**\n * The name of the object.\n */\n name: string\n}\n\nexport interface IStoredFile {\n /**\n * The kind of the File\n */\n kind: string\n /**\n * The identifier of the entity\n */\n key: string\n /**\n * The parent organization of the file.\n */\n organization: string\n /**\n * The file's meta info.\n */\n info: IThing\n /**\n * The owner of this object. The id of the User object.\n * Once the File is persistent by the API this is always populated.\n */\n owner?: string\n /**\n * The color of the icon to render for this file in the file explorer.\n * This should be a hex format, e.g.: #c00 for red.\n */\n iconColor?: string\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n isShortcut?: boolean\n /**\n * The ID of the target file.\n */\n shortcutTarget?: string\n}\n\n/**\n * An interface describing an object in the data store that\n * describes a file or an object that can be treated as a file or a folder.\n */\nexport interface IFile extends IStoredFile {\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * After creating the object, this property cannot be manipulated directly by the client.\n * Should be treated as opaque value.\n */\n parents: string[]\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n permissionIds: string[]\n /**\n * Whether the file object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * The last modification made to this file.\n */\n lastModified: IModification\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[]\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n capabilities?: ICapabilities\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n *\n * Data store implementation note, this is not stored in the store but it is populated\n * when reading the object.\n */\n permissions: IPermission[]\n /**\n * Populated by the store in some situations. If it's missing then you should request\n * breadcrumbs from the store.\n */\n breadcrumb?: FileBreadcrumb[]\n}\n\nconst parentsSymbol = Symbol('parents')\nconst deletedSymbol = Symbol('deleted')\nconst deletedInfoSymbol = Symbol('deletedInfo')\nconst ownerSymbol = Symbol('owner')\nconst lastModifiedSymbol = Symbol('lastModified')\nconst capabilitiesSymbol = Symbol('capabilities')\nconst permissionsSymbol = Symbol('permissions')\nconst permissionIdsSymbol = Symbol('permissionIds')\nconst shortcutTargetSymbol = Symbol('shortcutTarget')\n\nexport class StoredFile {\n /**\n * The kind of the File\n */\n kind = ''\n /**\n * The identifier of the entity\n */\n key = ''\n /**\n * The parent organization of the file.\n */\n organization = ''\n /**\n * The name of the environment.\n */\n info: Thing = Thing.fromName('');\n\n [ownerSymbol]?: string\n\n /**\n * The owner of this file. This is the id of the User object.\n * Set to `default` when there are no users in the system (no authentication).\n */\n get owner(): string | undefined {\n return this[ownerSymbol]\n }\n\n /**\n * The color of the icon to render for this file in the file explorer.\n */\n iconColor?: string\n\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n get isShortcut(): boolean {\n return !!this.shortcutTarget\n }\n\n [shortcutTargetSymbol]?: string\n\n /**\n * The ID of the target file.\n */\n get shortcutTarget(): string | undefined {\n return this[shortcutTargetSymbol]\n }\n\n set shortcutTarget(value: string | undefined) {\n this[shortcutTargetSymbol] = value\n }\n\n new(init: IStoredFile): this {\n const { key = v4(), info, kind, owner, iconColor, organization, shortcutTarget } = init\n this.key = key\n this.organization = organization\n this.kind = kind\n this[ownerSymbol] = owner\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (iconColor) {\n this.iconColor = iconColor\n } else {\n this.iconColor = undefined\n }\n if (shortcutTarget) {\n this.shortcutTarget = shortcutTarget\n } else {\n this.shortcutTarget = undefined\n }\n return this\n }\n\n toJSON(): IStoredFile {\n const { owner } = this\n const result: IStoredFile = {\n key: this.key,\n organization: this.organization,\n kind: this.kind,\n info: this.info.toJSON(),\n owner,\n }\n if (this.iconColor) {\n result.iconColor = this.iconColor\n }\n if (this.shortcutTarget) {\n result.isShortcut = true\n result.shortcutTarget = this.shortcutTarget\n }\n return result\n }\n\n /**\n * Creates the Capabilities object for a file giving user level.\n *\n * @param file The file object to create the capabilities to. The object is not mutated.\n * @param role The user role to the file.\n */\n static createFileCapabilities(file: IStoredFile | StoredFile, role?: PermissionRole): ICapabilities {\n const isCommenter = Permission.hasRole('commenter', role)\n const isOwner = Permission.hasRole('owner', role)\n const isReader = Permission.hasRole('reader', role)\n const isWriter = Permission.hasRole('writer', role)\n const isFolder = file.kind === FolderKind\n const result: ICapabilities = {\n canReadMedia: !isFolder && isReader,\n canListChildren: isFolder && isReader,\n canComment: !isFolder && isCommenter,\n canEditMedia: !isFolder && isWriter,\n canEditMeta: isWriter,\n canReadRevisions: isWriter,\n canAddChildren: isFolder && isWriter,\n canDelete: isOwner,\n canTrash: isOwner,\n canUntrash: isOwner,\n canShare: isWriter,\n canMove: isWriter,\n }\n return result\n }\n\n createFileCapabilities(role: PermissionRole): ICapabilities {\n return File.createFileCapabilities(this, role)\n }\n\n /**\n * Mutates the file object by setting the `byMe` properties (on deleted and modified info)\n *\n * Note, this can be done only on file schema (IFile). The `File` object has\n * this properties frozen.\n *\n * @param file The file to mutate\n * @param user The user key to compare.\n */\n static updateByMeMeta(file: IFile, user: string): void {\n if (file.deletedInfo) {\n file.deletedInfo.byMe = file.deletedInfo.user === user\n }\n if (file.lastModified) {\n file.lastModified.byMe = file.lastModified.user === user\n }\n }\n\n /**\n * Static method to set the `lastModified` property on a file without creating an instance of a file meta.\n * Useful when the meta kind is unknown.\n *\n * @param file The file to update. Note, this method mutates the file.\n * @param user The user that modifies the file.\n * @returns The same file.\n */\n static setLastModified(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n file.lastModified = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n\n /**\n * Similar to the instance method `setDeleted()` but without creating\n * an instance of the file when the type is unknown.\n *\n * @param file The file to change. Note, this operation mutates the file.\n * @param user The deleting user\n * @returns The same file reference.\n */\n static setDeleted(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n file.deleted = true\n file.deletedInfo = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n}\n\nexport class File extends StoredFile {\n [parentsSymbol]: string[] = []\n\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get parents(): string[] {\n return this[parentsSymbol]\n }\n\n [permissionIdsSymbol]: readonly string[] = []\n\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissionIds(): readonly string[] {\n return this[permissionIdsSymbol]\n }\n\n [deletedSymbol]?: boolean\n\n /**\n * Whether the file object is deleted.\n */\n get deleted(): boolean {\n return this[deletedSymbol] || false\n }\n\n [deletedInfoSymbol]?: Readonly<IDeletion>\n\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n get deletedInfo(): Readonly<IDeletion> | undefined {\n return this[deletedInfoSymbol]\n }\n\n [lastModifiedSymbol]: Readonly<IModification> = { user: '', time: 0, byMe: false }\n\n /**\n * The last modification made to this file.\n */\n get lastModified(): Readonly<IModification> {\n return this[lastModifiedSymbol]\n }\n\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[];\n\n [capabilitiesSymbol]?: Readonly<ICapabilities>\n\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n get capabilities(): Readonly<ICapabilities> | undefined {\n return this[capabilitiesSymbol]\n }\n\n [permissionsSymbol]: readonly IPermission[] = []\n\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissions(): readonly IPermission[] {\n return this[permissionsSymbol]\n }\n\n override new(init: IFile): this {\n super.new(init)\n const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init\n this[permissionsSymbol] = permissions.map((i) => ({ ...i }))\n this[parentsSymbol] = [...parents]\n this[permissionIdsSymbol] = [...permissionIds]\n this[lastModifiedSymbol] = lastModified\n ? Object.freeze({ ...lastModified })\n : Object.freeze({ user: '', time: 0, byMe: false })\n if (typeof deleted === 'boolean') {\n this[deletedSymbol] = deleted\n this[deletedInfoSymbol] = deletedInfo ? Object.freeze({ ...deletedInfo }) : undefined\n } else {\n this[deletedSymbol] = undefined\n this[deletedInfoSymbol] = undefined\n }\n if (Array.isArray(labels)) {\n this.labels = [...labels]\n } else {\n this.labels = undefined\n }\n return this\n }\n\n override toJSON(): IFile {\n const result: IFile = {\n ...super.toJSON(),\n parents: [...this.parents],\n permissionIds: [...this.permissionIds],\n lastModified: { ...this.lastModified },\n permissions: [...this.permissions],\n }\n if (this.deleted) {\n result.deleted = this.deleted\n result.deletedInfo = { ...this.deletedInfo } as IDeletion\n }\n if (Array.isArray(this.labels)) {\n result.labels = [...this.labels]\n }\n return result\n }\n\n /**\n * @param name The name to set.\n * @param owner The user id that is the owner of the file.\n */\n static fromName(name: string, organization: string, owner?: string, kind = ''): File {\n const key = v4()\n const definition = new File()\n definition.new({\n key,\n kind,\n organization,\n info: Thing.fromName(name).toJSON(),\n owner,\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: owner || '', time: 0, byMe: false },\n })\n return definition\n }\n\n shortcutTo(fileId: string): this {\n this.shortcutTarget = fileId\n return this\n }\n\n /**\n * Updates the \"lastModified\" value.\n * A helper method for a common task.\n *\n * @param user The user that modifies the entity.\n */\n setLastModified(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n this[lastModifiedSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n /**\n * Adds a label to the list of labels.\n *\n * It makes sure the value is a valid, non-empty string and the `labels` array is set.\n *\n * It does nothing when the label already exists.\n *\n * @param label The label to set.\n */\n addLabel(label: string): void {\n if (typeof label !== 'string') {\n throw new Error(`The label must be a string.`)\n }\n if (!label.trim()) {\n throw new Error(`The label is required.`)\n }\n if (!Array.isArray(this.labels)) {\n this.labels = []\n }\n if (this.labels.includes(label)) {\n return\n }\n this.labels.push(label)\n }\n\n /**\n * Marks the entity as deleted.\n *\n * A helper method for a common task.\n *\n * @param user The user that deletes the entity.\n */\n setDeleted(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n this[deletedSymbol] = true\n this[deletedInfoSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n isFile(): boolean {\n return this.kind !== FolderKind\n }\n\n isFolder(): boolean {\n return this.kind === FolderKind\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"File.js","sourceRoot":"","sources":["../../../../src/models/store/File.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAe,UAAU,EAAkB,MAAM,iBAAiB,CAAA;AAGzE,OAAO,EAAS,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAwIxC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AACvC,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAC/C,MAAM,mBAAmB,GAAG,MAAM,CAAC,eAAe,CAAC,C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AAA;QAC1B,IAAI,CAAC,iBAAiB,CAAC,GAAG;YACxB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { IPermission, Permission, PermissionRole } from './Permission.js'\nimport { IModification } from './Modification.js'\nimport { IDeletion } from './Deletion.js'\nimport { IUser, Kind as UserKind } from './User.js'\nimport { IThing, Thing } from '../Thing.js'\nimport { ICapabilities } from './Capabilities.js'\nimport { FolderKind } from '../kinds.js'\n// this causes error\n// import { Kind as FolderKind } from '../Folder.js';\n\nexport interface FileAddOptions {\n /**\n * The parent folder where to put the file.\n * The `parents` array is always cleared from the file object before adding it to the store.\n */\n parent?: string\n}\n\nexport interface MediaReadOptions {\n /**\n * When set it reads the file that was marked as `_deleted`. By default it throws when file was deleted.\n */\n deleted?: boolean\n}\n\n/**\n * A breadcrumb when creating the breadcrumb list for a file.\n */\nexport interface FileBreadcrumb {\n /**\n * The datastore key of the object.\n */\n key: string\n /**\n * THe kind of the object.\n */\n kind: string\n /**\n * The name of the object.\n */\n name: string\n}\n\nexport interface IStoredFile {\n /**\n * The kind of the File\n */\n kind: string\n /**\n * The identifier of the entity\n */\n key: string\n /**\n * The parent organization of the file.\n */\n organization: string\n /**\n * The file's meta info.\n */\n info: IThing\n /**\n * The owner of this object. The id of the User object.\n * Once the File is persistent by the API this is always populated.\n */\n owner?: string\n /**\n * The color of the icon to render for this file in the file explorer.\n * This should be a hex format, e.g.: #c00 for red.\n */\n iconColor?: string\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n isShortcut?: boolean\n /**\n * The ID of the target file.\n */\n shortcutTarget?: string\n}\n\n/**\n * An interface describing an object in the data store that\n * describes a file or an object that can be treated as a file or a folder.\n */\nexport interface IFile extends IStoredFile {\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * After creating the object, this property cannot be manipulated directly by the client.\n * Should be treated as opaque value.\n */\n parents: string[]\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n permissionIds: string[]\n /**\n * Whether the file object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * The last modification made to this file.\n */\n lastModified: IModification\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[]\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n capabilities?: ICapabilities\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n *\n * Data store implementation note, this is not stored in the store but it is populated\n * when reading the object.\n */\n permissions: IPermission[]\n /**\n * Populated by the store in some situations. If it's missing then you should request\n * breadcrumbs from the store.\n */\n breadcrumb?: FileBreadcrumb[]\n}\n\nconst parentsSymbol = Symbol('parents')\nconst deletedSymbol = Symbol('deleted')\nconst deletedInfoSymbol = Symbol('deletedInfo')\nconst ownerSymbol = Symbol('owner')\nconst lastModifiedSymbol = Symbol('lastModified')\nconst capabilitiesSymbol = Symbol('capabilities')\nconst permissionsSymbol = Symbol('permissions')\nconst permissionIdsSymbol = Symbol('permissionIds')\nconst shortcutTargetSymbol = Symbol('shortcutTarget')\n\nexport class StoredFile {\n /**\n * The kind of the File\n */\n kind = ''\n /**\n * The identifier of the entity\n */\n key = ''\n /**\n * The parent organization of the file.\n */\n organization = ''\n /**\n * The name of the environment.\n */\n info: Thing = Thing.fromName('');\n\n [ownerSymbol]?: string\n\n /**\n * The owner of this file. This is the id of the User object.\n * Set to `default` when there are no users in the system (no authentication).\n */\n get owner(): string | undefined {\n return this[ownerSymbol]\n }\n\n /**\n * The color of the icon to render for this file in the file explorer.\n */\n iconColor?: string\n\n /**\n * Whether the file is a shortcut to another file.\n * Many properties cannot be changed of a shortcut, like, shortcuts cannot be shared.\n */\n get isShortcut(): boolean {\n return !!this.shortcutTarget\n }\n\n [shortcutTargetSymbol]?: string\n\n /**\n * The ID of the target file.\n */\n get shortcutTarget(): string | undefined {\n return this[shortcutTargetSymbol]\n }\n\n set shortcutTarget(value: string | undefined) {\n this[shortcutTargetSymbol] = value\n }\n\n new(init: IStoredFile): this {\n const { key = nanoid(), info, kind, owner, iconColor, organization, shortcutTarget } = init\n this.key = key\n this.organization = organization\n this.kind = kind\n this[ownerSymbol] = owner\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (iconColor) {\n this.iconColor = iconColor\n } else {\n this.iconColor = undefined\n }\n if (shortcutTarget) {\n this.shortcutTarget = shortcutTarget\n } else {\n this.shortcutTarget = undefined\n }\n return this\n }\n\n toJSON(): IStoredFile {\n const { owner } = this\n const result: IStoredFile = {\n key: this.key,\n organization: this.organization,\n kind: this.kind,\n info: this.info.toJSON(),\n owner,\n }\n if (this.iconColor) {\n result.iconColor = this.iconColor\n }\n if (this.shortcutTarget) {\n result.isShortcut = true\n result.shortcutTarget = this.shortcutTarget\n }\n return result\n }\n\n /**\n * Creates the Capabilities object for a file giving user level.\n *\n * @param file The file object to create the capabilities to. The object is not mutated.\n * @param role The user role to the file.\n */\n static createFileCapabilities(file: IStoredFile | StoredFile, role?: PermissionRole): ICapabilities {\n const isCommenter = Permission.hasRole('commenter', role)\n const isOwner = Permission.hasRole('owner', role)\n const isReader = Permission.hasRole('reader', role)\n const isWriter = Permission.hasRole('writer', role)\n const isFolder = file.kind === FolderKind\n const result: ICapabilities = {\n canReadMedia: !isFolder && isReader,\n canListChildren: isFolder && isReader,\n canComment: !isFolder && isCommenter,\n canEditMedia: !isFolder && isWriter,\n canEditMeta: isWriter,\n canReadRevisions: isWriter,\n canAddChildren: isFolder && isWriter,\n canDelete: isOwner,\n canTrash: isOwner,\n canUntrash: isOwner,\n canShare: isWriter,\n canMove: isWriter,\n }\n return result\n }\n\n createFileCapabilities(role: PermissionRole): ICapabilities {\n return File.createFileCapabilities(this, role)\n }\n\n /**\n * Mutates the file object by setting the `byMe` properties (on deleted and modified info)\n *\n * Note, this can be done only on file schema (IFile). The `File` object has\n * this properties frozen.\n *\n * @param file The file to mutate\n * @param user The user key to compare.\n */\n static updateByMeMeta(file: IFile, user: string): void {\n if (file.deletedInfo) {\n file.deletedInfo.byMe = file.deletedInfo.user === user\n }\n if (file.lastModified) {\n file.lastModified.byMe = file.lastModified.user === user\n }\n }\n\n /**\n * Static method to set the `lastModified` property on a file without creating an instance of a file meta.\n * Useful when the meta kind is unknown.\n *\n * @param file The file to update. Note, this method mutates the file.\n * @param user The user that modifies the file.\n * @returns The same file.\n */\n static setLastModified(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n file.lastModified = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n\n /**\n * Similar to the instance method `setDeleted()` but without creating\n * an instance of the file when the type is unknown.\n *\n * @param file The file to change. Note, this operation mutates the file.\n * @param user The deleting user\n * @returns The same file reference.\n */\n static setDeleted(file: IFile, user: IUser): IFile {\n if (!file) {\n throw new Error(`The file is required.`)\n }\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n file.deleted = true\n file.deletedInfo = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n return file\n }\n}\n\nexport class File extends StoredFile {\n [parentsSymbol]: string[] = []\n\n /**\n * The list of parents of the object. It is an ordered list of parents\n * from the top (first element) to the lowest parent in the tree (last element).\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get parents(): string[] {\n return this[parentsSymbol]\n }\n\n [permissionIdsSymbol]: readonly string[] = []\n\n /**\n * The list of permissions to this file object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissionIds(): readonly string[] {\n return this[permissionIdsSymbol]\n }\n\n [deletedSymbol]?: boolean\n\n /**\n * Whether the file object is deleted.\n */\n get deleted(): boolean {\n return this[deletedSymbol] || false\n }\n\n [deletedInfoSymbol]?: Readonly<IDeletion>\n\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n get deletedInfo(): Readonly<IDeletion> | undefined {\n return this[deletedInfoSymbol]\n }\n\n [lastModifiedSymbol]: Readonly<IModification> = { user: '', time: 0, byMe: false }\n\n /**\n * The last modification made to this file.\n */\n get lastModified(): Readonly<IModification> {\n return this[lastModifiedSymbol]\n }\n\n /**\n * An arbitrary list of labels applied to the file.\n */\n labels?: string[];\n\n [capabilitiesSymbol]?: Readonly<ICapabilities>\n\n /**\n * This is populated when reading a file from the store.\n * A list of actions the user can perform on the file.\n *\n * This is a readonly field and it is ignored when creating / updating the file.\n */\n get capabilities(): Readonly<ICapabilities> | undefined {\n return this[capabilitiesSymbol]\n }\n\n [permissionsSymbol]: readonly IPermission[] = []\n\n /**\n * Populated by the server when reading the file. The list of permissions to the object.\n *\n * This property cannot be manipulated directly by the client. Should be treated as\n * opaque value.\n */\n get permissions(): readonly IPermission[] {\n return this[permissionsSymbol]\n }\n\n override new(init: IFile): this {\n super.new(init)\n const { permissions = [], parents = [], permissionIds = [], deleted, deletedInfo, lastModified, labels } = init\n this[permissionsSymbol] = permissions.map((i) => ({ ...i }))\n this[parentsSymbol] = [...parents]\n this[permissionIdsSymbol] = [...permissionIds]\n this[lastModifiedSymbol] = lastModified\n ? Object.freeze({ ...lastModified })\n : Object.freeze({ user: '', time: 0, byMe: false })\n if (typeof deleted === 'boolean') {\n this[deletedSymbol] = deleted\n this[deletedInfoSymbol] = deletedInfo ? Object.freeze({ ...deletedInfo }) : undefined\n } else {\n this[deletedSymbol] = undefined\n this[deletedInfoSymbol] = undefined\n }\n if (Array.isArray(labels)) {\n this.labels = [...labels]\n } else {\n this.labels = undefined\n }\n return this\n }\n\n override toJSON(): IFile {\n const result: IFile = {\n ...super.toJSON(),\n parents: [...this.parents],\n permissionIds: [...this.permissionIds],\n lastModified: { ...this.lastModified },\n permissions: [...this.permissions],\n }\n if (this.deleted) {\n result.deleted = this.deleted\n result.deletedInfo = { ...this.deletedInfo } as IDeletion\n }\n if (Array.isArray(this.labels)) {\n result.labels = [...this.labels]\n }\n return result\n }\n\n /**\n * @param name The name to set.\n * @param owner The user id that is the owner of the file.\n */\n static fromName(name: string, organization: string, owner?: string, kind = ''): File {\n const key = nanoid()\n const definition = new File()\n definition.new({\n key,\n kind,\n organization,\n info: Thing.fromName(name).toJSON(),\n owner,\n parents: [],\n permissionIds: [],\n permissions: [],\n lastModified: { user: owner || '', time: 0, byMe: false },\n })\n return definition\n }\n\n shortcutTo(fileId: string): this {\n this.shortcutTarget = fileId\n return this\n }\n\n /**\n * Updates the \"lastModified\" value.\n * A helper method for a common task.\n *\n * @param user The user that modifies the entity.\n */\n setLastModified(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"lastModified\".`)\n }\n this[lastModifiedSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n /**\n * Adds a label to the list of labels.\n *\n * It makes sure the value is a valid, non-empty string and the `labels` array is set.\n *\n * It does nothing when the label already exists.\n *\n * @param label The label to set.\n */\n addLabel(label: string): void {\n if (typeof label !== 'string') {\n throw new Error(`The label must be a string.`)\n }\n if (!label.trim()) {\n throw new Error(`The label is required.`)\n }\n if (!Array.isArray(this.labels)) {\n this.labels = []\n }\n if (this.labels.includes(label)) {\n return\n }\n this.labels.push(label)\n }\n\n /**\n * Marks the entity as deleted.\n *\n * A helper method for a common task.\n *\n * @param user The user that deletes the entity.\n */\n setDeleted(user: IUser): void {\n if (!user) {\n throw new Error(`The user is required.`)\n }\n if (user.kind !== UserKind) {\n throw new Error(`Invalid value for the user when setting \"deletedInfo\".`)\n }\n this[deletedSymbol] = true\n this[deletedInfoSymbol] = {\n byMe: false,\n time: Date.now(),\n user: user.key,\n name: user.name,\n }\n }\n\n isFile(): boolean {\n return this.kind !== FolderKind\n }\n\n isFolder(): boolean {\n return this.kind === FolderKind\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
2
|
export const Kind = 'Core#Organization';
|
|
3
3
|
export class Organization {
|
|
4
4
|
kind = Kind;
|
|
@@ -20,7 +20,7 @@ export class Organization {
|
|
|
20
20
|
else {
|
|
21
21
|
init = {
|
|
22
22
|
kind: Kind,
|
|
23
|
-
key:
|
|
23
|
+
key: nanoid(),
|
|
24
24
|
name: '',
|
|
25
25
|
createdBy: '',
|
|
26
26
|
createdDate: Date.now(),
|
|
@@ -34,7 +34,7 @@ export class Organization {
|
|
|
34
34
|
if (!Organization.isOrganization(init)) {
|
|
35
35
|
throw new Error(`Not an Organization.`);
|
|
36
36
|
}
|
|
37
|
-
const { key =
|
|
37
|
+
const { key = nanoid(), name, createdBy, createdDate = Date.now(), deleted = false, deletedInfo, grantType = 'member', } = init;
|
|
38
38
|
this.kind = Kind;
|
|
39
39
|
this.key = key;
|
|
40
40
|
this.name = name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Organization.js","sourceRoot":"","sources":["../../../../src/models/store/Organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,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id'\nimport type { IDeletion } from './Deletion.js'\n\nexport const Kind = 'Core#Organization'\n\nexport type UserOrganizationGrantType = 'owner' | 'member'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IOrganization {\n kind: typeof Kind\n /**\n * The database ID\n */\n key: string\n /**\n * The organization name\n */\n name: string\n /**\n * The key of the user that created the organization.\n */\n createdBy: string\n /**\n * The timestamp when the organization was created.\n */\n createdDate: number\n /**\n * Whether the organization object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * The grant type to the organization the **current user** has.\n * By nature, it's a dynamic field populated by the data store.\n */\n grantType: UserOrganizationGrantType\n}\n\nexport class Organization implements IOrganization {\n kind: typeof Kind = Kind\n key = ''\n name = ''\n createdBy = ''\n createdDate = 0\n deleted = false\n deletedInfo?: IDeletion\n grantType: UserOrganizationGrantType = 'member'\n\n constructor(input?: string | IOrganization) {\n let init: IOrganization\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n name: '',\n createdBy: '',\n createdDate: Date.now(),\n deleted: false,\n grantType: 'member',\n }\n }\n this.new(init)\n }\n\n new(init: IOrganization): void {\n if (!Organization.isOrganization(init)) {\n throw new Error(`Not an Organization.`)\n }\n const {\n key = nanoid(),\n name,\n createdBy,\n createdDate = Date.now(),\n deleted = false,\n deletedInfo,\n grantType = 'member',\n } = init\n this.kind = Kind\n this.key = key\n this.name = name\n this.createdBy = createdBy\n this.createdDate = createdDate\n this.deleted = deleted\n this.grantType = grantType\n if (deletedInfo) {\n this.deletedInfo = deletedInfo\n } else {\n this.deletedInfo = undefined\n }\n }\n\n /**\n * Checks whether the input is a definition of an user organization.\n */\n static isOrganization(input: unknown): boolean {\n const typed = input as IOrganization\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n toJSON(): IOrganization {\n const result: IOrganization = {\n kind: Kind,\n key: this.key,\n name: this.name,\n createdBy: this.createdBy,\n createdDate: this.createdDate,\n deleted: this.deleted,\n grantType: this.grantType,\n }\n if (this.deletedInfo) {\n result.deletedInfo = this.deletedInfo\n }\n return result\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
2
|
export const Kind = 'Core#Permission';
|
|
3
3
|
const orderedRoles = ['reader', 'commenter', 'writer', 'owner'];
|
|
4
4
|
export class Permission {
|
|
@@ -59,7 +59,7 @@ export class Permission {
|
|
|
59
59
|
*/
|
|
60
60
|
static fromUserRole(role, itemId, user, addingUser) {
|
|
61
61
|
const init = {
|
|
62
|
-
key:
|
|
62
|
+
key: nanoid(),
|
|
63
63
|
kind: Kind,
|
|
64
64
|
itemId,
|
|
65
65
|
granteeId: user,
|
|
@@ -79,7 +79,7 @@ export class Permission {
|
|
|
79
79
|
*/
|
|
80
80
|
static fromGroupRole(role, itemId, group, addingUser) {
|
|
81
81
|
const init = {
|
|
82
|
-
key:
|
|
82
|
+
key: nanoid(),
|
|
83
83
|
kind: Kind,
|
|
84
84
|
itemId,
|
|
85
85
|
granteeId: group,
|
|
@@ -98,7 +98,7 @@ export class Permission {
|
|
|
98
98
|
*/
|
|
99
99
|
static fromOrganizationRole(role, itemId, organizationId, addingUser) {
|
|
100
100
|
const init = {
|
|
101
|
-
key:
|
|
101
|
+
key: nanoid(),
|
|
102
102
|
kind: Kind,
|
|
103
103
|
itemId,
|
|
104
104
|
granteeId: organizationId,
|
|
@@ -114,7 +114,7 @@ export class Permission {
|
|
|
114
114
|
static fromValues(init) {
|
|
115
115
|
return new Permission({
|
|
116
116
|
...init,
|
|
117
|
-
key:
|
|
117
|
+
key: nanoid(),
|
|
118
118
|
kind: Kind,
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -129,7 +129,7 @@ export class Permission {
|
|
|
129
129
|
else {
|
|
130
130
|
init = {
|
|
131
131
|
kind: Kind,
|
|
132
|
-
key:
|
|
132
|
+
key: nanoid(),
|
|
133
133
|
granteeId: '',
|
|
134
134
|
itemId: '',
|
|
135
135
|
role: 'reader',
|
|
@@ -143,7 +143,7 @@ export class Permission {
|
|
|
143
143
|
if (!Permission.isPermission(init)) {
|
|
144
144
|
throw new Error(`Not a permission.`);
|
|
145
145
|
}
|
|
146
|
-
const { key =
|
|
146
|
+
const { key = nanoid(), granteeId, role, type, displayName, expirationTime, addingUser, itemId } = init;
|
|
147
147
|
this.kind = Kind;
|
|
148
148
|
this.key = key;
|
|
149
149
|
this.granteeId = granteeId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Permission.js","sourceRoot":"","sources":["../../../../src/models/store/Permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAElC,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAA;AAUrC,MAAM,YAAY,GAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;AA0DjF,MAAM,OAAO,UAAU;IACrB,IAAI,GAAG,IAAI,CAAA;IACX;;;OAGG;IACH,GAAG,GAAG,EAAE,CAAA;IACR;;;;;;OAMG;IACH,IAAI,GAAmB,MAAM,CAAA;IAC7B;;;OAGG;IACH,SAAS,GAAG,EAAE,CAAA;IACd;;OAEG;IACH,IAAI,GAAmB,QAAQ,CAAA;IAC/B;;;;;;OAMG;IACH,WAAW,CAAS;IACpB;;;;;;OAMG;IACH,cAAc,CAAS;IAEvB;;OAEG;IACH,UAAU,GAAG,EAAE,CAAA;IAEf;;OAEG;IACH,MAAM,GAAG,EAAE,CAAA;IAEX;;;;;;;OAOG;IACH,MAAM,CAAC,YAAY,CAAC,IAAoB,EAAE,MAAc,EAAE,IAAY,EAAE,UAAkB;QACxF,MAAM,IAAI,GAAgB;YACxB,GAAG,EAAE,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,CAAA;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import v4 from '../../lib/uuid.js'\n\nexport const Kind = 'Core#Permission'\n\nexport type PermissionType = 'user' | 'group' | 'organization'\n/**\n * - `owner`: Full control over the item.\n * - `writer`: Can view, comment, and edit the item.\n * - `commenter`: Can view and comment on the item.\n * - `reader`: Can only view the item.\n */\nexport type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer'\nconst orderedRoles: PermissionRole[] = ['reader', 'commenter', 'writer', 'owner']\n\ninterface IBasePermission {\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType\n /**\n * It represents the ID of the entity (user, group,or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId: string\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId: string\n /**\n * The role granted by this permission.\n */\n role: PermissionRole\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - no render name\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n /**\n * The store id of the user that added this permission.\n */\n addingUser: string\n}\n\n/**\n * A schema describing a permission to a store object.\n */\nexport interface IPermission extends IBasePermission {\n kind: typeof Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key: string\n}\n\nexport class Permission {\n kind = Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key = ''\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType = 'user'\n /**\n * It represents the ID of the entity (user, group, or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId = ''\n /**\n * The role granted by this permission.\n */\n role: PermissionRole = 'reader'\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - the organization name.\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n\n /**\n * The store id of the user that added this permission.\n */\n addingUser = ''\n\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId = ''\n\n /**\n * Creates a Permission object for a user.\n *\n * @param role The user role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param user The user id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromUserRole(role: PermissionRole, itemId: string, user: string, addingUser: string): Permission {\n const init: IPermission = {\n key: v4(),\n kind: Kind,\n itemId,\n granteeId: user,\n role,\n type: 'user',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param group The group id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromGroupRole(role: PermissionRole, itemId: string, group: string, addingUser: string): Permission {\n const init: IPermission = {\n key: v4(),\n kind: Kind,\n itemId,\n granteeId: group,\n role,\n type: 'group',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param addingUser The key of the user that created this permission\n */\n static fromOrganizationRole(\n role: PermissionRole,\n itemId: string,\n organizationId: string,\n addingUser: string\n ): Permission {\n const init: IPermission = {\n key: v4(),\n kind: Kind,\n itemId,\n granteeId: organizationId,\n role,\n type: 'organization',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a permission object from other than key and kind values.\n */\n static fromValues(init: IBasePermission): Permission {\n return new Permission({\n ...init,\n key: v4(),\n kind: Kind,\n })\n }\n\n constructor(input?: string | IPermission) {\n let init: IPermission\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: v4(),\n granteeId: '',\n itemId: '',\n role: 'reader',\n type: 'user',\n addingUser: '',\n }\n }\n this.new(init)\n }\n\n new(init: IPermission): void {\n if (!Permission.isPermission(init)) {\n throw new Error(`Not a permission.`)\n }\n const { key = v4(), granteeId, role, type, displayName, expirationTime, addingUser, itemId } = init\n this.kind = Kind\n this.key = key\n this.granteeId = granteeId\n this.itemId = itemId\n this.role = role\n this.type = type\n this.addingUser = addingUser\n if (displayName) {\n this.displayName = displayName\n } else {\n this.displayName = undefined\n }\n if (typeof expirationTime === 'number') {\n this.expirationTime = expirationTime\n } else {\n this.expirationTime = undefined\n }\n }\n\n static isPermission(input: unknown): boolean {\n const typed = input as IPermission\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Checks whether the current user role meets the minimum required role.\n *\n * @param minimumLevel The minimum requested role\n * @param currentRole The user role. When not set it always returns false.\n * @returns True if the `currentRole` is at least the `minimumRole`\n */\n static hasRole(minimumLevel: PermissionRole, currentRole?: PermissionRole): boolean {\n if (!currentRole) {\n return false\n }\n const currentAccessIndex = orderedRoles.indexOf(currentRole)\n const requestedAccessIndex = orderedRoles.indexOf(minimumLevel)\n // the current must be at least at the index of requested.\n return currentAccessIndex >= requestedAccessIndex\n }\n\n /**\n * Checks if role1 is higher than role2 in the permission hierarchy.\n *\n * @param role1 The first role to compare.\n * @param role2 The second role to compare.\n * @returns `true` if `role1` is higher than `role2`, `false` otherwise.\n */\n static isHigherRole(role1: PermissionRole, role2: PermissionRole): boolean {\n const role1Index = orderedRoles.indexOf(role1)\n const role2Index = orderedRoles.indexOf(role2)\n return role1Index > role2Index\n }\n\n /**\n * Link to the `Permission.hasRole(minimumLevel, currentRole)`.\n * @see {@link Permission.hasRole}\n */\n hasRole(minimumLevel: PermissionRole, currentRole: PermissionRole): boolean {\n return Permission.hasRole(minimumLevel, currentRole)\n }\n\n toJSON(): IPermission {\n const result: IPermission = {\n kind: Kind,\n key: this.key,\n role: this.role,\n type: this.type,\n addingUser: this.addingUser,\n granteeId: this.granteeId,\n itemId: this.itemId,\n }\n if (this.displayName) {\n result.displayName = this.displayName\n }\n if (this.expirationTime) {\n result.expirationTime = this.expirationTime\n }\n return result\n }\n}\n\n/**\n * This is used in the communication with the backend to add/change user's access to the resource.\n */\nexport interface IAccessOperation {\n /**\n * The user, group, or organization id that this permission affects.\n */\n id: string\n /**\n * The permission type: user, group, or organization\n */\n type: PermissionType\n}\n\ninterface IUpdatingOperation {\n /**\n * The level that the user or the group has access to:\n * - owner\n * - reader\n * - commenter\n * - writer\n */\n value: PermissionRole\n /**\n * The timestamp when the permission expires.\n */\n expirationTime?: number\n}\n\nexport interface IAccessAddOperation extends IAccessOperation, IUpdatingOperation {\n op: 'add'\n}\n\nexport interface IAccessRemoveOperation extends IAccessOperation {\n op: 'remove'\n}\n\nexport interface IAccessUpdateOperation extends IAccessOperation, IUpdatingOperation {\n op: 'update'\n /**\n * The ID of the permission to update.\n */\n id: string\n}\n\nexport type AccessOperation = IAccessAddOperation | IAccessRemoveOperation | IAccessUpdateOperation\n"]}
|
|
1
|
+
{"version":3,"file":"Permission.js","sourceRoot":"","sources":["../../../../src/models/store/Permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAA;AAUrC,MAAM,YAAY,GAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;AA0DjF,MAAM,OAAO,UA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G,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC9C,OAAO,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,YAA4B,EAAE,WAA2B;QAC/D,OAAO,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IACtD,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAgB;YAC1B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;QACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\n\nexport const Kind = 'Core#Permission'\n\nexport type PermissionType = 'user' | 'group' | 'organization'\n/**\n * - `owner`: Full control over the item.\n * - `writer`: Can view, comment, and edit the item.\n * - `commenter`: Can view and comment on the item.\n * - `reader`: Can only view the item.\n */\nexport type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer'\nconst orderedRoles: PermissionRole[] = ['reader', 'commenter', 'writer', 'owner']\n\ninterface IBasePermission {\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType\n /**\n * It represents the ID of the entity (user, group,or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId: string\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId: string\n /**\n * The role granted by this permission.\n */\n role: PermissionRole\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - no render name\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n /**\n * The store id of the user that added this permission.\n */\n addingUser: string\n}\n\n/**\n * A schema describing a permission to a store object.\n */\nexport interface IPermission extends IBasePermission {\n kind: typeof Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key: string\n}\n\nexport class Permission {\n kind = Kind\n /**\n * The data store key of the permission.\n * This property is generated by the store and is not writable.\n */\n key = ''\n /**\n * The type of the permission.\n *\n * - `user` can access the file by a specific user\n * - `group` can access the file by a group of users\n * - - `organization` the object can be searched by anyone within the organization.\n */\n type: PermissionType = 'user'\n /**\n * It represents the ID of the entity (user, group, or organization)\n * that is being granted the permission on a file or folder.\n */\n granteeId = ''\n /**\n * The role granted by this permission.\n */\n role: PermissionRole = 'reader'\n /**\n * The \"pretty\" name to render with the permission.\n *\n * - `user` type - user's full name\n * - `group` type - the name of the group\n * - `organization` type - the organization name.\n */\n displayName?: string\n /**\n * Optional expiration date of the permission. This is the timestamp when the permission expires.\n * When creating / updating the permission the expiration date must:\n *\n * - be used on a user or a group\n * - the time must be in the future\n */\n expirationTime?: number\n\n /**\n * The store id of the user that added this permission.\n */\n addingUser = ''\n\n /**\n * The store id of the entity that is being granted the permission.\n */\n itemId = ''\n\n /**\n * Creates a Permission object for a user.\n *\n * @param role The user role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param user The user id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromUserRole(role: PermissionRole, itemId: string, user: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: user,\n role,\n type: 'user',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param group The group id that has the role.\n * @param addingUser The key of the user that created this permission\n */\n static fromGroupRole(role: PermissionRole, itemId: string, group: string, addingUser: string): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: group,\n role,\n type: 'group',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a Permission object for a group.\n *\n * @param role The group role to set.\n * @param itemId The store id of the entity that is being granted the permission.\n * @param addingUser The key of the user that created this permission\n */\n static fromOrganizationRole(\n role: PermissionRole,\n itemId: string,\n organizationId: string,\n addingUser: string\n ): Permission {\n const init: IPermission = {\n key: nanoid(),\n kind: Kind,\n itemId,\n granteeId: organizationId,\n role,\n type: 'organization',\n addingUser,\n }\n return new Permission(init)\n }\n\n /**\n * Creates a permission object from other than key and kind values.\n */\n static fromValues(init: IBasePermission): Permission {\n return new Permission({\n ...init,\n key: nanoid(),\n kind: Kind,\n })\n }\n\n constructor(input?: string | IPermission) {\n let init: IPermission\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n granteeId: '',\n itemId: '',\n role: 'reader',\n type: 'user',\n addingUser: '',\n }\n }\n this.new(init)\n }\n\n new(init: IPermission): void {\n if (!Permission.isPermission(init)) {\n throw new Error(`Not a permission.`)\n }\n const { key = nanoid(), granteeId, role, type, displayName, expirationTime, addingUser, itemId } = init\n this.kind = Kind\n this.key = key\n this.granteeId = granteeId\n this.itemId = itemId\n this.role = role\n this.type = type\n this.addingUser = addingUser\n if (displayName) {\n this.displayName = displayName\n } else {\n this.displayName = undefined\n }\n if (typeof expirationTime === 'number') {\n this.expirationTime = expirationTime\n } else {\n this.expirationTime = undefined\n }\n }\n\n static isPermission(input: unknown): boolean {\n const typed = input as IPermission\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n /**\n * Checks whether the current user role meets the minimum required role.\n *\n * @param minimumLevel The minimum requested role\n * @param currentRole The user role. When not set it always returns false.\n * @returns True if the `currentRole` is at least the `minimumRole`\n */\n static hasRole(minimumLevel: PermissionRole, currentRole?: PermissionRole): boolean {\n if (!currentRole) {\n return false\n }\n const currentAccessIndex = orderedRoles.indexOf(currentRole)\n const requestedAccessIndex = orderedRoles.indexOf(minimumLevel)\n // the current must be at least at the index of requested.\n return currentAccessIndex >= requestedAccessIndex\n }\n\n /**\n * Checks if role1 is higher than role2 in the permission hierarchy.\n *\n * @param role1 The first role to compare.\n * @param role2 The second role to compare.\n * @returns `true` if `role1` is higher than `role2`, `false` otherwise.\n */\n static isHigherRole(role1: PermissionRole, role2: PermissionRole): boolean {\n const role1Index = orderedRoles.indexOf(role1)\n const role2Index = orderedRoles.indexOf(role2)\n return role1Index > role2Index\n }\n\n /**\n * Link to the `Permission.hasRole(minimumLevel, currentRole)`.\n * @see {@link Permission.hasRole}\n */\n hasRole(minimumLevel: PermissionRole, currentRole: PermissionRole): boolean {\n return Permission.hasRole(minimumLevel, currentRole)\n }\n\n toJSON(): IPermission {\n const result: IPermission = {\n kind: Kind,\n key: this.key,\n role: this.role,\n type: this.type,\n addingUser: this.addingUser,\n granteeId: this.granteeId,\n itemId: this.itemId,\n }\n if (this.displayName) {\n result.displayName = this.displayName\n }\n if (this.expirationTime) {\n result.expirationTime = this.expirationTime\n }\n return result\n }\n}\n\n/**\n * This is used in the communication with the backend to add/change user's access to the resource.\n */\nexport interface IAccessOperation {\n /**\n * The user, group, or organization id that this permission affects.\n */\n id: string\n /**\n * The permission type: user, group, or organization\n */\n type: PermissionType\n}\n\ninterface IUpdatingOperation {\n /**\n * The level that the user or the group has access to:\n * - owner\n * - reader\n * - commenter\n * - writer\n */\n value: PermissionRole\n /**\n * The timestamp when the permission expires.\n */\n expirationTime?: number\n}\n\nexport interface IAccessAddOperation extends IAccessOperation, IUpdatingOperation {\n op: 'add'\n}\n\nexport interface IAccessRemoveOperation extends IAccessOperation {\n op: 'remove'\n}\n\nexport interface IAccessUpdateOperation extends IAccessOperation, IUpdatingOperation {\n op: 'update'\n /**\n * The ID of the permission to update.\n */\n id: string\n}\n\nexport type AccessOperation = IAccessAddOperation | IAccessRemoveOperation | IAccessUpdateOperation\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
2
|
export const Kind = 'Core#UserIdentity';
|
|
3
3
|
export class UserIdentity {
|
|
4
4
|
kind = Kind;
|
|
@@ -19,7 +19,7 @@ export class UserIdentity {
|
|
|
19
19
|
else {
|
|
20
20
|
init = {
|
|
21
21
|
kind: Kind,
|
|
22
|
-
key:
|
|
22
|
+
key: nanoid(),
|
|
23
23
|
userId: '',
|
|
24
24
|
provider: 'google',
|
|
25
25
|
providerId: '',
|
|
@@ -32,7 +32,7 @@ export class UserIdentity {
|
|
|
32
32
|
if (!UserIdentity.isUserIdentity(init)) {
|
|
33
33
|
throw new Error(`Not a UserIdentity.`);
|
|
34
34
|
}
|
|
35
|
-
const { key =
|
|
35
|
+
const { key = nanoid(), emailVerified, provider, providerId, userId, hostDomain } = init;
|
|
36
36
|
this.kind = Kind;
|
|
37
37
|
this.key = key;
|
|
38
38
|
this.provider = provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserIdentity.js","sourceRoot":"","sources":["../../../../src/models/store/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"UserIdentity.js","sourceRoot":"","sources":["../../../../src/models/store/UserIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,CAAC,MAAM,IAAI,GAAG,mBAAmB,CAAA;AAuCvC,MAAM,OAAO,YAAY;IACvB,IAAI,GAAgB,IAAI,CAAA;IACxB,GAAG,G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EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC9B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC7B,CAAC;IACH,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,KAAc;QAClC,MAAM,KAAK,GAAG,KAAsB,CAAA;QACpC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAkB;YAC5B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAA;QACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACrC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\n\nexport const Kind = 'Core#UserIdentity'\n\ntype Provider = 'google'\n\n/**\n * In the system the user identity represents registration information associated with a specific identity provider.\n * This association allows the user to use different identity providers that map to the same user, as long as the\n * email stays consistent.\n */\nexport interface IUserIdentity {\n kind: typeof Kind\n /**\n * The database ID\n */\n key: string\n /**\n * The related user id.\n */\n userId: string\n /**\n * The identity provider.\n */\n provider: Provider\n /**\n * The provider's unique ID.\n * This allows to recognize a returning user.\n */\n providerId: string\n /**\n * `true`, if the provider has verified the email address.\n */\n emailVerified: boolean\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hostDomain?: string\n}\n\nexport class UserIdentity implements IUserIdentity {\n kind: typeof Kind = Kind\n key = ''\n userId = ''\n provider: Provider = 'google'\n providerId = ''\n emailVerified = false\n hostDomain?: string\n\n constructor(input?: string | IUserIdentity) {\n let init: IUserIdentity\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: Kind,\n key: nanoid(),\n userId: '',\n provider: 'google',\n providerId: '',\n emailVerified: false,\n }\n }\n this.new(init)\n }\n\n new(init: IUserIdentity): void {\n if (!UserIdentity.isUserIdentity(init)) {\n throw new Error(`Not a UserIdentity.`)\n }\n const { key = nanoid(), emailVerified, provider, providerId, userId, hostDomain } = init\n this.kind = Kind\n this.key = key\n this.provider = provider\n this.providerId = providerId\n this.userId = userId\n this.emailVerified = emailVerified\n if (hostDomain) {\n this.hostDomain = hostDomain\n } else {\n this.hostDomain = undefined\n }\n }\n\n static isUserIdentity(input: unknown): boolean {\n const typed = input as IUserIdentity\n if (!input || typed.kind !== Kind) {\n return false\n }\n return true\n }\n\n toJSON(): IUserIdentity {\n const result: IUserIdentity = {\n kind: Kind,\n key: this.key,\n provider: this.provider,\n providerId: this.providerId,\n userId: this.userId,\n emailVerified: this.emailVerified,\n }\n if (this.hostDomain) {\n result.hostDomain = this.hostDomain\n }\n return result\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
2
|
import { BaseTransformer, dataValue } from './BaseTransformer.js';
|
|
3
3
|
/**
|
|
4
4
|
* Transforms Dexie system (legacy system) into the legacy PouchDB system.
|
|
@@ -63,7 +63,7 @@ export class ArcDexieTransformer extends BaseTransformer {
|
|
|
63
63
|
updateData: item.requestIds,
|
|
64
64
|
legacyProject: {
|
|
65
65
|
kind: 'ARC#Project',
|
|
66
|
-
key:
|
|
66
|
+
key: nanoid(),
|
|
67
67
|
name: item.name,
|
|
68
68
|
order: item.order,
|
|
69
69
|
updated: item.updateTime,
|
|
@@ -132,7 +132,7 @@ export class ArcDexieTransformer extends BaseTransformer {
|
|
|
132
132
|
const updated = { ...item };
|
|
133
133
|
updated.updateTime = updated.updateTime || Date.now();
|
|
134
134
|
const obj = {
|
|
135
|
-
key:
|
|
135
|
+
key: nanoid(),
|
|
136
136
|
method: updated.method,
|
|
137
137
|
url: updated.url,
|
|
138
138
|
updated: new Date(updated.updateTime).getTime(),
|
|
@@ -172,7 +172,7 @@ export class ArcDexieTransformer extends BaseTransformer {
|
|
|
172
172
|
url: item.url,
|
|
173
173
|
type: 'saved',
|
|
174
174
|
kind: 'ARC#HttpRequest',
|
|
175
|
-
key:
|
|
175
|
+
key: nanoid(),
|
|
176
176
|
};
|
|
177
177
|
// payload and headers
|
|
178
178
|
const harIndex = item.referenceEntry || 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcDexieTransformer.js","sourceRoot":"","sources":["../../../../src/models/transformers/ArcDexieTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAkEjE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACtD;;;;;OAKG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAgB,CAAA;QAE1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACpD,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE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AO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;gBACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;oBAClC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;wBACjC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;wBACjC,OAAO,CAAC,GAAG,IAAI,IAAI,YAAY,EAAE,CAAA;wBACjC,IAAI,CAAC,mBAAmB,CAAC,OAAgC,EAAE,YAAY,CAAC,CAAA;wBACxE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;wBAC5D,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import v4 from '../../lib/uuid.js'\nimport { BaseTransformer, dataValue } from './BaseTransformer.js'\nimport { Creator, Browser, Page, Entry, Header } from './har.js'\nimport {\n ArcExportObject,\n ExportArcProjects,\n ExportArcSavedRequest,\n ExportArcHistoryRequest,\n} from '../legacy/DataExport.js'\n\ninterface DexieExport {\n kind: string\n createdAt: string\n version: string\n requests?: DexieRequest[]\n projects?: DexieProject[]\n}\ninterface DexieRequest {\n order: number\n url: string\n method: string\n type: string\n updateTime: number\n id: string\n kind: string\n har: DexieHar\n _har?: DexieHar\n name?: string\n _name?: string\n referenceEntry?: number\n driveId?: string\n}\n\ninterface DexieHar {\n comment: string\n version: string\n creator: Creator\n browser: Browser\n pages: Page[]\n entries: Entry[]\n}\n\ninterface DexieProject {\n order: number\n created: number\n updateTime: number\n requestIds: string[]\n name: string\n kind: string\n id: number\n}\n\ninterface ProjectItem {\n updateData: string[]\n legacyProject: ExportArcProjects\n}\n\ninterface RequestProcessItem {\n origin: string\n request: ExportArcSavedRequest | ExportArcHistoryRequest\n}\n\ninterface ProcessedRequests {\n saved: RequestProcessItem[]\n history: RequestProcessItem[]\n}\n\n/**\n * Transforms Dexie system (legacy system) into the legacy PouchDB system.\n */\nexport class ArcDexieTransformer extends BaseTransformer {\n /**\n * Transforms legacy ARC export object based on Dexie data store\n * into current export data model.\n *\n * @returns New data model object.\n */\n async transform(): Promise<ArcExportObject> {\n const raw = this[dataValue] as DexieExport\n\n const requests = await this.parseRequests(raw.requests || [])\n const pData = this.processProjects(raw.projects || [])\n const data = this.associateProjects(requests, pData)\n const result = {\n createdAt: new Date().toISOString(),\n version: 'unknown',\n kind: 'ARC#Import',\n requests: data.saved ? data.saved.map((item) => item.request as ExportArcSavedRequest) : [],\n projects: pData ? pData.map((item) => item.legacyProject as ExportArcProjects) : [],\n history: data.history ? data.history.map((item) => item.request as ExportArcHistoryRequest) : [],\n }\n // TODO: handle history data.\n return result\n }\n\n /**\n * In new structure projects do not have a reference to request ids. It's\n * the other way around in previous system.\n * It's a bad pattern for object stores but it must suffice for now.\n *\n * @param projects List of projects in the import.\n * @returns Preprocessed projects array\n */\n processProjects(projects: DexieProject[]): ProjectItem[] {\n if (!projects || !projects.length) {\n return []\n }\n const list: ProjectItem[] = []\n projects.forEach((item) => {\n const result = this.processProjectItem(item)\n if (result) {\n list.push(result)\n }\n })\n return list\n }\n\n /**\n * Creates a pre-processed project data.\n *\n * @param item Project object from the Dexie import.\n * @return Pre-processed project object with project store data\n * under the `legacyProject` property and list of requests IDs under\n * the `updateData` property.\n */\n processProjectItem(item: DexieProject): ProjectItem | undefined {\n if (!item.requestIds || !item.requestIds.length) {\n return undefined\n }\n return {\n updateData: item.requestIds,\n legacyProject: {\n kind: 'ARC#Project',\n key: v4(),\n name: item.name,\n order: item.order,\n updated: item.updateTime,\n created: item.created,\n },\n }\n }\n\n /**\n * History is placed in its own store, saved items has own store.\n * Har data are not imported this way as user cannot actually use it.\n *\n * @param requests List of requests objects from the import file.\n * @returns A promise resolved when import is ready.\n */\n async parseRequests(requests: DexieRequest[]): Promise<ProcessedRequests> {\n const data = await this.parseRequestsDeffered(requests)\n // remove duplicates from the history.\n const ids: string[] = []\n data.history = data.history.filter((item) => {\n if (ids.indexOf(item.request.key) === -1) {\n ids[ids.length] = item.request.key\n return true\n }\n return false\n })\n return data\n }\n\n /**\n * Parses the request data.\n * It takes only portion of the data to parse so the script release the\n * event loop and ANR screen won't appear.\n *\n * @param requests List of requests from the import.\n * @param saved Final list of saved requests\n * @param history Final list of history items.\n */\n async parseRequestsDeffered(\n requests: DexieRequest[],\n saved: RequestProcessItem[] = [],\n history: RequestProcessItem[] = []\n ): Promise<ProcessedRequests> {\n if (requests.length === 0) {\n return {\n saved,\n history,\n }\n }\n const len = Math.min(requests.length, 200)\n // Up to 200 loop iteration at once.\n // Then the function return and release main loop.\n for (let i = 0; i < len; i++) {\n const item = requests[i]\n if (item.type === 'history') {\n const result = this.parseHistoryItem(item)\n history.push(result)\n } else if (item.type === 'saved') {\n const result = this.parseSavedItem(item)\n saved.push(result)\n } else if (item.type === 'drive') {\n const result = this.parseDriveItem(item)\n saved.push(result)\n }\n }\n requests.splice(0, len)\n return this.parseRequestsDeffered(requests, saved, history)\n }\n\n parseHistoryItem(item: DexieRequest): RequestProcessItem {\n const updated = { ...item }\n updated.updateTime = updated.updateTime || Date.now()\n const obj: ExportArcHistoryRequest = {\n key: v4(),\n method: updated.method,\n url: updated.url,\n updated: new Date(updated.updateTime).getTime(),\n }\n // payload and headers\n const har = updated._har || updated.har\n const { entries } = har\n const entry = entries[entries.length - 1]\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n } else {\n obj.created = obj.updated\n }\n obj.updated = Date.now()\n return {\n origin: updated.id,\n request: obj,\n }\n }\n\n parseSavedItem(item: DexieRequest): RequestProcessItem {\n const requestName = item.name || item._name\n let keyName = requestName\n if (keyName && keyName[0] === '_') {\n keyName = keyName.substr(1)\n }\n const obj: ExportArcSavedRequest = {\n name: requestName || '',\n method: item.method,\n url: item.url,\n type: 'saved',\n kind: 'ARC#HttpRequest',\n key: v4(),\n }\n // payload and headers\n const harIndex = item.referenceEntry || 0\n const har = item._har || item.har\n if (har) {\n const { entries } = har\n let entry\n if (harIndex || harIndex === 0) {\n entry = entries[harIndex]\n } else {\n ;[entry] = entries\n }\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n }\n }\n obj.updated = Date.now()\n\n return {\n origin: item.id,\n request: obj,\n }\n }\n\n parseDriveItem(item: DexieRequest): RequestProcessItem {\n const result = this.parseSavedItem(item)\n result.request.driveId = item.driveId\n return result\n }\n\n parseHarHeaders(arr: Header[]): string {\n if (!arr || !arr.length) {\n return ''\n }\n return arr.map((item) => `${item.name}: ${item.value}`).join('\\n')\n }\n\n /**\n * Associate requests with project data.\n *\n * @param {ProcessedRequests} data Parsed requests object\n * @param {ProjectItem[]} projects List of projects\n * @return {ProcessedRequests} Parsed requests object\n */\n associateProjects(data: ProcessedRequests, projects: ProjectItem[]): ProcessedRequests {\n if (!projects || !projects.length) {\n return data\n }\n if (!data.saved) {\n data.saved = []\n }\n const savedLen = data.saved.length\n const projectsLen = projects.length\n for (let i = 0; i < projectsLen; i++) {\n const project = projects[i]\n const newProjectId = project.legacyProject.key\n for (let j = 0, rLen = project.updateData.length; j < rLen; j++) {\n const rId = project.updateData[j]\n for (let k = 0; k < savedLen; k++) {\n if (data.saved[k].origin === rId) {\n const { request } = data.saved[k]\n request.key += `/${newProjectId}`\n this.addProjectReference(request as ExportArcSavedRequest, newProjectId)\n this.addRequestReference(project.legacyProject, request.key)\n break\n }\n }\n }\n }\n return data\n }\n}\n"]}
|
|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,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;wBAC5D,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { nanoid } from 'nanoid'\nimport { BaseTransformer, dataValue } from './BaseTransformer.js'\nimport { Creator, Browser, Page, Entry, Header } from './har.js'\nimport {\n ArcExportObject,\n ExportArcProjects,\n ExportArcSavedRequest,\n ExportArcHistoryRequest,\n} from '../legacy/DataExport.js'\n\ninterface DexieExport {\n kind: string\n createdAt: string\n version: string\n requests?: DexieRequest[]\n projects?: DexieProject[]\n}\ninterface DexieRequest {\n order: number\n url: string\n method: string\n type: string\n updateTime: number\n id: string\n kind: string\n har: DexieHar\n _har?: DexieHar\n name?: string\n _name?: string\n referenceEntry?: number\n driveId?: string\n}\n\ninterface DexieHar {\n comment: string\n version: string\n creator: Creator\n browser: Browser\n pages: Page[]\n entries: Entry[]\n}\n\ninterface DexieProject {\n order: number\n created: number\n updateTime: number\n requestIds: string[]\n name: string\n kind: string\n id: number\n}\n\ninterface ProjectItem {\n updateData: string[]\n legacyProject: ExportArcProjects\n}\n\ninterface RequestProcessItem {\n origin: string\n request: ExportArcSavedRequest | ExportArcHistoryRequest\n}\n\ninterface ProcessedRequests {\n saved: RequestProcessItem[]\n history: RequestProcessItem[]\n}\n\n/**\n * Transforms Dexie system (legacy system) into the legacy PouchDB system.\n */\nexport class ArcDexieTransformer extends BaseTransformer {\n /**\n * Transforms legacy ARC export object based on Dexie data store\n * into current export data model.\n *\n * @returns New data model object.\n */\n async transform(): Promise<ArcExportObject> {\n const raw = this[dataValue] as DexieExport\n\n const requests = await this.parseRequests(raw.requests || [])\n const pData = this.processProjects(raw.projects || [])\n const data = this.associateProjects(requests, pData)\n const result = {\n createdAt: new Date().toISOString(),\n version: 'unknown',\n kind: 'ARC#Import',\n requests: data.saved ? data.saved.map((item) => item.request as ExportArcSavedRequest) : [],\n projects: pData ? pData.map((item) => item.legacyProject as ExportArcProjects) : [],\n history: data.history ? data.history.map((item) => item.request as ExportArcHistoryRequest) : [],\n }\n // TODO: handle history data.\n return result\n }\n\n /**\n * In new structure projects do not have a reference to request ids. It's\n * the other way around in previous system.\n * It's a bad pattern for object stores but it must suffice for now.\n *\n * @param projects List of projects in the import.\n * @returns Preprocessed projects array\n */\n processProjects(projects: DexieProject[]): ProjectItem[] {\n if (!projects || !projects.length) {\n return []\n }\n const list: ProjectItem[] = []\n projects.forEach((item) => {\n const result = this.processProjectItem(item)\n if (result) {\n list.push(result)\n }\n })\n return list\n }\n\n /**\n * Creates a pre-processed project data.\n *\n * @param item Project object from the Dexie import.\n * @return Pre-processed project object with project store data\n * under the `legacyProject` property and list of requests IDs under\n * the `updateData` property.\n */\n processProjectItem(item: DexieProject): ProjectItem | undefined {\n if (!item.requestIds || !item.requestIds.length) {\n return undefined\n }\n return {\n updateData: item.requestIds,\n legacyProject: {\n kind: 'ARC#Project',\n key: nanoid(),\n name: item.name,\n order: item.order,\n updated: item.updateTime,\n created: item.created,\n },\n }\n }\n\n /**\n * History is placed in its own store, saved items has own store.\n * Har data are not imported this way as user cannot actually use it.\n *\n * @param requests List of requests objects from the import file.\n * @returns A promise resolved when import is ready.\n */\n async parseRequests(requests: DexieRequest[]): Promise<ProcessedRequests> {\n const data = await this.parseRequestsDeffered(requests)\n // remove duplicates from the history.\n const ids: string[] = []\n data.history = data.history.filter((item) => {\n if (ids.indexOf(item.request.key) === -1) {\n ids[ids.length] = item.request.key\n return true\n }\n return false\n })\n return data\n }\n\n /**\n * Parses the request data.\n * It takes only portion of the data to parse so the script release the\n * event loop and ANR screen won't appear.\n *\n * @param requests List of requests from the import.\n * @param saved Final list of saved requests\n * @param history Final list of history items.\n */\n async parseRequestsDeffered(\n requests: DexieRequest[],\n saved: RequestProcessItem[] = [],\n history: RequestProcessItem[] = []\n ): Promise<ProcessedRequests> {\n if (requests.length === 0) {\n return {\n saved,\n history,\n }\n }\n const len = Math.min(requests.length, 200)\n // Up to 200 loop iteration at once.\n // Then the function return and release main loop.\n for (let i = 0; i < len; i++) {\n const item = requests[i]\n if (item.type === 'history') {\n const result = this.parseHistoryItem(item)\n history.push(result)\n } else if (item.type === 'saved') {\n const result = this.parseSavedItem(item)\n saved.push(result)\n } else if (item.type === 'drive') {\n const result = this.parseDriveItem(item)\n saved.push(result)\n }\n }\n requests.splice(0, len)\n return this.parseRequestsDeffered(requests, saved, history)\n }\n\n parseHistoryItem(item: DexieRequest): RequestProcessItem {\n const updated = { ...item }\n updated.updateTime = updated.updateTime || Date.now()\n const obj: ExportArcHistoryRequest = {\n key: nanoid(),\n method: updated.method,\n url: updated.url,\n updated: new Date(updated.updateTime).getTime(),\n }\n // payload and headers\n const har = updated._har || updated.har\n const { entries } = har\n const entry = entries[entries.length - 1]\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n } else {\n obj.created = obj.updated\n }\n obj.updated = Date.now()\n return {\n origin: updated.id,\n request: obj,\n }\n }\n\n parseSavedItem(item: DexieRequest): RequestProcessItem {\n const requestName = item.name || item._name\n let keyName = requestName\n if (keyName && keyName[0] === '_') {\n keyName = keyName.substr(1)\n }\n const obj: ExportArcSavedRequest = {\n name: requestName || '',\n method: item.method,\n url: item.url,\n type: 'saved',\n kind: 'ARC#HttpRequest',\n key: nanoid(),\n }\n // payload and headers\n const harIndex = item.referenceEntry || 0\n const har = item._har || item.har\n if (har) {\n const { entries } = har\n let entry\n if (harIndex || harIndex === 0) {\n entry = entries[harIndex]\n } else {\n ;[entry] = entries\n }\n if (entry) {\n const harRequest = entry.request\n obj.headers = this.parseHarHeaders(harRequest.headers)\n obj.payload = harRequest.postData?.text\n let t = new Date(entry.startedDateTime).getTime()\n if (Number.isNaN(t)) {\n t = Date.now()\n }\n obj.created = t\n }\n }\n obj.updated = Date.now()\n\n return {\n origin: item.id,\n request: obj,\n }\n }\n\n parseDriveItem(item: DexieRequest): RequestProcessItem {\n const result = this.parseSavedItem(item)\n result.request.driveId = item.driveId\n return result\n }\n\n parseHarHeaders(arr: Header[]): string {\n if (!arr || !arr.length) {\n return ''\n }\n return arr.map((item) => `${item.name}: ${item.value}`).join('\\n')\n }\n\n /**\n * Associate requests with project data.\n *\n * @param {ProcessedRequests} data Parsed requests object\n * @param {ProjectItem[]} projects List of projects\n * @return {ProcessedRequests} Parsed requests object\n */\n associateProjects(data: ProcessedRequests, projects: ProjectItem[]): ProcessedRequests {\n if (!projects || !projects.length) {\n return data\n }\n if (!data.saved) {\n data.saved = []\n }\n const savedLen = data.saved.length\n const projectsLen = projects.length\n for (let i = 0; i < projectsLen; i++) {\n const project = projects[i]\n const newProjectId = project.legacyProject.key\n for (let j = 0, rLen = project.updateData.length; j < rLen; j++) {\n const rId = project.updateData[j]\n for (let k = 0; k < savedLen; k++) {\n if (data.saved[k].origin === rId) {\n const { request } = data.saved[k]\n request.key += `/${newProjectId}`\n this.addProjectReference(request as ExportArcSavedRequest, newProjectId)\n this.addRequestReference(project.legacyProject, request.key)\n break\n }\n }\n }\n }\n return data\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
3
|
import { BaseTransformer, dataValue } from './BaseTransformer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Tests if the data import is a single request export.
|
|
@@ -71,7 +71,7 @@ export class ArcLegacyTransformer extends BaseTransformer {
|
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
73
|
kind: 'ARC#ProjectData',
|
|
74
|
-
key:
|
|
74
|
+
key: nanoid(),
|
|
75
75
|
created,
|
|
76
76
|
name: item.name || 'unnamed',
|
|
77
77
|
order: 0,
|
|
@@ -108,7 +108,7 @@ export class ArcLegacyTransformer extends BaseTransformer {
|
|
|
108
108
|
item.method = item.method || 'GET';
|
|
109
109
|
const project = this.findProject(item.project, projects);
|
|
110
110
|
const projectId = project ? project.key : undefined;
|
|
111
|
-
const id =
|
|
111
|
+
const id = nanoid();
|
|
112
112
|
let created = Number(item.time);
|
|
113
113
|
if (Number.isNaN(created)) {
|
|
114
114
|
created = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcLegacyTransformer.js","sourceRoot":"","sources":["../../../../src/models/transformers/ArcLegacyTransformer.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ArcLegacyTransformer.js","sourceRoot":"","sources":["../../../../src/models/transformers/ArcLegacyTransformer.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAuCjE;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAS;IACvC,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IACvD;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAQ,CAAA;QAElC,IAAI,QAAyC,CAAA;QAC7C,IAAI,QAA6C,CAAA;QACjD,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,GAAoB,CAAA;YACjC,QAAQ,GAAG,EAAE,CAAA;YACb,QAAQ,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1C,CAAC;aAAM,CAA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;YACP,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;YAC3B,IAAI,EAAE,OAAO;YACb,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;QACD,IAAI,OAAO,IAAI,SAAS,EAAE,CAAC;YACzB,MAAM,CAAC,QAAQ,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACvC,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,SAAiB,EAAE,QAAoC;QACjE,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAA;IACvD,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { nanoid } from 'nanoid'\nimport { BaseTransformer, dataValue } from './BaseTransformer.js'\nimport { ArcExportObject, ExportArcProjects, ExportArcSavedRequest } from '../legacy/DataExport.js'\n\ninterface LegacyExport {\n requests: LegacyRequest[]\n projects: LegacyProject[]\n}\n\ninterface LegacyRequest {\n id: number\n name: string\n project: number\n url: string\n method: string\n encoding: string | null\n headers: string | null\n payload: string | null\n skipProtocol: boolean\n skipServer: boolean\n skipParams: boolean\n skipHistory: boolean\n skipMethod: boolean\n skipPayload: boolean\n skipHeaders: boolean\n skipPath: boolean\n time: number\n driveId?: string | null\n}\n\ninterface LegacyProject {\n created: number\n id: number\n name: string\n}\n\ninterface LegacyProjectProcessing extends ExportArcProjects {\n originId: number\n}\n\n/**\n * Tests if the data import is a single request export.\n *\n * @param data Imported data\n * @return True if `data` represents single request\n */\nexport function isSingleRequest(data: any): boolean {\n if ('requests' in data || 'projects' in data) {\n return false\n }\n return true\n}\n\n/**\n * Transforms the first ARC data object to current schema.\n */\nexport class ArcLegacyTransformer extends BaseTransformer {\n /**\n * Transforms legacy ARC export object into current export data model.\n *\n * @return New data model object.\n */\n async transform(): Promise<ArcExportObject> {\n const raw = this[dataValue] as any\n\n let projects: ExportArcProjects[] | undefined\n let requests: ExportArcSavedRequest[] | undefined\n if (isSingleRequest(raw)) {\n const item = raw as LegacyRequest\n projects = []\n requests = [this.transformRequest(item)]\n } else {\n const data = raw as LegacyExport\n const tmp = (projects = this.transformProjects(data.projects))\n requests = this.transformRequests(data.requests, tmp)\n projects = projects.map((item) => {\n // @ts-expect-error I think this whole library is going away.\n delete item.originId\n return item\n })\n }\n\n const result: ArcExportObject = {\n createdAt: new Date().toISOString(),\n version: 'unknown',\n kind: 'ARC#Import',\n requests,\n projects,\n }\n\n return result\n }\n\n /**\n * Returns a list of projects from a legacy export file.\n *\n * Each project will have newly generated ID to not make conflicts with\n * existing projects. Old project id is moved to the `originId` property.\n *\n * @param projects List of legacy project objects\n * @returns List of project object in current data model. It can be\n * empty array.\n */\n transformProjects(projects: LegacyProject[]): LegacyProjectProcessing[] {\n if (!projects || !(projects instanceof Array) || !projects.length) {\n return []\n }\n return projects.map((item) => {\n let created = Number(item.created)\n if (Number.isNaN(created)) {\n created = Date.now()\n }\n return {\n kind: 'ARC#ProjectData',\n key: nanoid(),\n created,\n name: item.name || 'unnamed',\n order: 0,\n updated: Date.now(),\n originId: item.id,\n }\n })\n }\n\n /**\n * Transform the list of requests into new data model.\n */\n transformRequests(requests: LegacyRequest[], projects?: LegacyProjectProcessing[]): ExportArcSavedRequest[] {\n if (!requests || !(requests instanceof Array) || !requests.length) {\n return []\n }\n return requests.map((item) => this.transformRequest(item, projects))\n }\n\n /**\n * Transforms a single request object into current data model.\n *\n * Note that required properties will be default to the following:\n * - `name` - \"unnamed\"\n * - `url` - \"http://\"\n * - `method` - \"GET\"\n *\n * @param item Legacy request definition\n * @param projects List of projects in the import file.\n * @return Current model of the request object.\n */\n transformRequest(item: LegacyRequest, projects?: LegacyProjectProcessing[]): ExportArcSavedRequest {\n // LegacyRequest may have `null` values.\n item.name = item.name || 'unnamed'\n item.url = item.url || 'http://'\n item.method = item.method || 'GET'\n\n const project = this.findProject(item.project, projects)\n const projectId = project ? project.key : undefined\n const id = nanoid()\n let created = Number(item.time)\n if (Number.isNaN(created)) {\n created = Date.now()\n }\n const result: ExportArcSavedRequest = {\n kind: 'ARC#HttpRequest',\n key: id,\n created,\n updated: Date.now(),\n headers: item.headers || '',\n method: item.method,\n name: item.name,\n payload: item.payload || '',\n type: 'saved',\n url: item.url,\n }\n if (project && projectId) {\n result.projects = [projectId]\n this.addRequestReference(project, id)\n }\n if (item.driveId) {\n result.driveId = item.driveId\n }\n return result\n }\n\n /**\n * Finds a project in the list of projects.\n *\n * @param projectId A project ID to search for\n * @param projects List of project to look into. It compares the `originId` property of the list items.\n * @returns A project object or null if not found.\n */\n findProject(projectId: number, projects?: LegacyProjectProcessing[]): LegacyProjectProcessing | undefined {\n if (!projectId || !Array.isArray(projects)) {\n return undefined\n }\n return projects.find((p) => p.originId === projectId)\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
3
|
import { BaseTransformer, dataValue } from './BaseTransformer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Updates `updated` property and ensures `created` property
|
|
@@ -80,7 +80,7 @@ export class ArcPouchTransformer extends BaseTransformer {
|
|
|
80
80
|
return projects.map((item) => {
|
|
81
81
|
const project = { ...item };
|
|
82
82
|
if (!project.key) {
|
|
83
|
-
project.key =
|
|
83
|
+
project.key = nanoid();
|
|
84
84
|
}
|
|
85
85
|
return updateItemTimings(project);
|
|
86
86
|
});
|