@kinotic-ai/core 5.0.0-beta.19 → 5.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +75 -110
- package/dist/index.d.cts +110 -97
- package/dist/index.d.ts +110 -97
- package/dist/index.js +75 -110
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -66,10 +66,11 @@ var exports_src = {};
|
|
|
66
66
|
__export(exports_src, {
|
|
67
67
|
validateZone: () => validateZone,
|
|
68
68
|
validateLabel: () => validateLabel,
|
|
69
|
-
serviceContractOf: () => serviceContractOf,
|
|
70
69
|
scopeOptionalMethodNames: () => scopeOptionalMethodNames,
|
|
71
70
|
receivesContext: () => receivesContext,
|
|
72
71
|
isAdvertised: () => isAdvertised,
|
|
72
|
+
declaresAuthzResource: () => declaresAuthzResource,
|
|
73
|
+
declareServiceDefinitions: () => declareServiceDefinitions,
|
|
73
74
|
createCRI: () => createCRI,
|
|
74
75
|
buildServerUrl: () => buildServerUrl,
|
|
75
76
|
buildBrokerUrl: () => buildBrokerUrl,
|
|
@@ -1183,8 +1184,7 @@ var versionRegistry = new WeakMap;
|
|
|
1183
1184
|
var zonesRegistry = new WeakMap;
|
|
1184
1185
|
var advertisedRegistry = new WeakMap;
|
|
1185
1186
|
var contextMarkedFunctions = new WeakSet;
|
|
1186
|
-
var
|
|
1187
|
-
var authzCheckRegistry = new WeakMap;
|
|
1187
|
+
var authzResourceClasses = new WeakSet;
|
|
1188
1188
|
function findInConstructorChain(registry, constructor) {
|
|
1189
1189
|
let current = constructor;
|
|
1190
1190
|
while (current) {
|
|
@@ -1276,97 +1276,19 @@ function resolveEffectiveZone(constructor) {
|
|
|
1276
1276
|
return effectiveZone;
|
|
1277
1277
|
}
|
|
1278
1278
|
function AuthzResource(declaration) {
|
|
1279
|
-
const resource = typeof declaration === "string" ? { value: declaration } : declaration;
|
|
1280
|
-
if (!resource.value) {
|
|
1281
|
-
throw new Error("AuthzResource must name the resource type");
|
|
1282
|
-
}
|
|
1283
1279
|
return function(value, _context) {
|
|
1284
|
-
|
|
1280
|
+
authzResourceClasses.add(value);
|
|
1285
1281
|
};
|
|
1286
1282
|
}
|
|
1287
1283
|
function AuthzCheck(declaration) {
|
|
1288
|
-
return function(
|
|
1289
|
-
authzCheckRegistry.set(value, declaration);
|
|
1290
|
-
};
|
|
1284
|
+
return function(_value, _context) {};
|
|
1291
1285
|
}
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1294
|
-
let
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
const functions = [];
|
|
1300
|
-
const seen = new Set;
|
|
1301
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1302
|
-
while (proto && proto !== Object.prototype) {
|
|
1303
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1304
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1305
|
-
if (typeof descriptor?.value === "function" && key !== "constructor" && !seen.has(key)) {
|
|
1306
|
-
seen.add(key);
|
|
1307
|
-
const method = descriptor.value;
|
|
1308
|
-
const parameters = parameterNames(method);
|
|
1309
|
-
if (contextMarkedFunctions.has(method)) {
|
|
1310
|
-
parameters.pop();
|
|
1311
|
-
}
|
|
1312
|
-
functions.push({ name: key, parameters, check: authzCheckRegistry.get(method) ?? null });
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
proto = Object.getPrototypeOf(proto);
|
|
1316
|
-
}
|
|
1317
|
-
ret = {
|
|
1318
|
-
namespace: serviceIdentifier.namespace,
|
|
1319
|
-
name: serviceIdentifier.name,
|
|
1320
|
-
version: serviceIdentifier.version ?? null,
|
|
1321
|
-
zone: serviceIdentifier.zone,
|
|
1322
|
-
resource,
|
|
1323
|
-
functions
|
|
1324
|
-
};
|
|
1325
|
-
}
|
|
1326
|
-
return ret;
|
|
1327
|
-
}
|
|
1328
|
-
function parameterNames(method) {
|
|
1329
|
-
const source = method.toString().replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1330
|
-
let depth = 0;
|
|
1331
|
-
let start = -1;
|
|
1332
|
-
let end = -1;
|
|
1333
|
-
for (let i = 0;i < source.length && end < 0; i++) {
|
|
1334
|
-
const c = source[i];
|
|
1335
|
-
if (c === "(") {
|
|
1336
|
-
if (depth === 0 && start < 0) {
|
|
1337
|
-
start = i + 1;
|
|
1338
|
-
}
|
|
1339
|
-
depth++;
|
|
1340
|
-
} else if (c === ")") {
|
|
1341
|
-
depth--;
|
|
1342
|
-
if (depth === 0 && start >= 0) {
|
|
1343
|
-
end = i;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
const ret = [];
|
|
1348
|
-
if (start >= 0 && end >= 0) {
|
|
1349
|
-
let nested = 0;
|
|
1350
|
-
let current = "";
|
|
1351
|
-
const parts = [];
|
|
1352
|
-
for (const c of source.substring(start, end)) {
|
|
1353
|
-
if ("([{".includes(c)) {
|
|
1354
|
-
nested++;
|
|
1355
|
-
} else if (")]}".includes(c)) {
|
|
1356
|
-
nested--;
|
|
1357
|
-
}
|
|
1358
|
-
if (c === "," && nested === 0) {
|
|
1359
|
-
parts.push(current);
|
|
1360
|
-
current = "";
|
|
1361
|
-
} else {
|
|
1362
|
-
current += c;
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
parts.push(current);
|
|
1366
|
-
parts.map((part) => (part.split("=")[0] ?? "").trim()).filter((part) => part.length > 0).forEach((part, index) => {
|
|
1367
|
-
const name = part.replace(/^\.\.\./, "");
|
|
1368
|
-
ret.push(/^[A-Za-z_$][\w$]*$/.test(name) ? name : `arg${index}`);
|
|
1369
|
-
});
|
|
1286
|
+
function declaresAuthzResource(serviceInstance) {
|
|
1287
|
+
let ret = false;
|
|
1288
|
+
let current = serviceInstance.constructor;
|
|
1289
|
+
while (current && !ret) {
|
|
1290
|
+
ret = authzResourceClasses.has(current);
|
|
1291
|
+
current = Object.getPrototypeOf(current);
|
|
1370
1292
|
}
|
|
1371
1293
|
return ret;
|
|
1372
1294
|
}
|
|
@@ -1397,7 +1319,7 @@ var import_api2 = __toESM(require("@opentelemetry/api"));
|
|
|
1397
1319
|
// packages/core/package.json
|
|
1398
1320
|
var package_default = {
|
|
1399
1321
|
name: "@kinotic-ai/core",
|
|
1400
|
-
version: "5.0.0-beta.
|
|
1322
|
+
version: "5.0.0-beta.20",
|
|
1401
1323
|
type: "module",
|
|
1402
1324
|
files: [
|
|
1403
1325
|
"dist"
|
|
@@ -1466,6 +1388,7 @@ var package_default = {
|
|
|
1466
1388
|
vitest: "^4.1.4"
|
|
1467
1389
|
},
|
|
1468
1390
|
dependencies: {
|
|
1391
|
+
"@kinotic-ai/idl": "workspace:*",
|
|
1469
1392
|
"@opentelemetry/api": "^1.9.1",
|
|
1470
1393
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1471
1394
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1856,13 +1779,61 @@ class TextEventFactory {
|
|
|
1856
1779
|
return event;
|
|
1857
1780
|
}
|
|
1858
1781
|
}
|
|
1859
|
-
var
|
|
1782
|
+
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1860
1783
|
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1784
|
+
var declaredDefinitions = new Map;
|
|
1785
|
+
function declareServiceDefinitions(definitions) {
|
|
1786
|
+
for (const definition of definitions) {
|
|
1787
|
+
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
function qualifiedNameOf(namespace, name) {
|
|
1791
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
1792
|
+
}
|
|
1793
|
+
function servedFunctions(serviceInstance) {
|
|
1794
|
+
const ret = new Set;
|
|
1795
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1796
|
+
while (proto && proto !== Object.prototype) {
|
|
1797
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1798
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1799
|
+
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1800
|
+
ret.add(key);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
proto = Object.getPrototypeOf(proto);
|
|
1804
|
+
}
|
|
1805
|
+
return [...ret].sort();
|
|
1806
|
+
}
|
|
1807
|
+
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1808
|
+
let ret = null;
|
|
1809
|
+
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1810
|
+
if (application) {
|
|
1811
|
+
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1812
|
+
const definition = declaredDefinitions.get(qualifiedName);
|
|
1813
|
+
if (definition) {
|
|
1814
|
+
const declared = definition.functions.map((f) => f.name).sort();
|
|
1815
|
+
const served = servedFunctions(serviceInstance);
|
|
1816
|
+
if (declared.join() !== served.join()) {
|
|
1817
|
+
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1818
|
+
}
|
|
1819
|
+
ret = {
|
|
1820
|
+
applicationId: application[1],
|
|
1821
|
+
zone: serviceIdentifier.zone,
|
|
1822
|
+
version: serviceIdentifier.version ?? null,
|
|
1823
|
+
advertised: isAdvertised(serviceInstance),
|
|
1824
|
+
serviceDefinition: definition
|
|
1825
|
+
};
|
|
1826
|
+
} else if (declaresAuthzResource(serviceInstance)) {
|
|
1827
|
+
throw new Error(`${qualifiedName} declares a resource but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
return ret;
|
|
1831
|
+
}
|
|
1861
1832
|
|
|
1862
1833
|
class ServiceRegistry {
|
|
1863
1834
|
_eventBus;
|
|
1864
1835
|
supervisors = new Map;
|
|
1865
|
-
|
|
1836
|
+
entries = new Map;
|
|
1866
1837
|
contextInterceptor = null;
|
|
1867
1838
|
debugLogger = import_debug3.default("kinotic:serviceRegistry");
|
|
1868
1839
|
constructor(eventBus) {
|
|
@@ -1884,14 +1855,14 @@ class ServiceRegistry {
|
|
|
1884
1855
|
const criString = serviceIdentifier.cri().raw();
|
|
1885
1856
|
if (!this.supervisors.has(criString)) {
|
|
1886
1857
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1887
|
-
const
|
|
1858
|
+
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1888
1859
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1889
1860
|
this.supervisors.set(criString, supervisor);
|
|
1890
1861
|
supervisor.start();
|
|
1891
|
-
if (
|
|
1892
|
-
this.
|
|
1862
|
+
if (entry) {
|
|
1863
|
+
this.entries.set(criString, entry);
|
|
1893
1864
|
if (this.eventBus.isConnected()) {
|
|
1894
|
-
this.
|
|
1865
|
+
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1895
1866
|
}
|
|
1896
1867
|
}
|
|
1897
1868
|
}
|
|
@@ -1903,23 +1874,17 @@ class ServiceRegistry {
|
|
|
1903
1874
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1904
1875
|
supervisor.stop();
|
|
1905
1876
|
this.supervisors.delete(criString);
|
|
1906
|
-
this.
|
|
1877
|
+
this.entries.delete(criString);
|
|
1907
1878
|
}
|
|
1908
1879
|
}
|
|
1909
|
-
async
|
|
1910
|
-
for (const
|
|
1911
|
-
await this.
|
|
1880
|
+
async registerEntries() {
|
|
1881
|
+
for (const entry of this.entries.values()) {
|
|
1882
|
+
await this.registerEntry(entry);
|
|
1912
1883
|
}
|
|
1913
1884
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
async publishContract(contract) {
|
|
1918
|
-
const application = APPLICATION_ZONE.exec(contract.zone);
|
|
1919
|
-
if (application) {
|
|
1920
|
-
this.debugLogger(`Publishing the contract of ${contract.zone}~${contract.namespace}.${contract.name}`);
|
|
1921
|
-
await this.serviceProxy(SERVICE_CONTRACT_SERVICE).invoke("register", [application[1], contract]);
|
|
1922
|
-
}
|
|
1885
|
+
async registerEntry(entry) {
|
|
1886
|
+
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1887
|
+
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1923
1888
|
}
|
|
1924
1889
|
registerContextInterceptor(interceptor) {
|
|
1925
1890
|
this.contextInterceptor = interceptor;
|
|
@@ -2014,7 +1979,7 @@ class KinoticSingleton {
|
|
|
2014
1979
|
}
|
|
2015
1980
|
async connect(options) {
|
|
2016
1981
|
const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
2017
|
-
await this.serviceRegistry.
|
|
1982
|
+
await this.serviceRegistry.registerEntries();
|
|
2018
1983
|
return ret;
|
|
2019
1984
|
}
|
|
2020
1985
|
disconnect(force) {
|
package/dist/index.d.cts
CHANGED
|
@@ -647,70 +647,7 @@ interface IServiceRegistry {
|
|
|
647
647
|
*/
|
|
648
648
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
649
|
}
|
|
650
|
-
|
|
651
|
-
* A role a service declares for its resource type, named `<type>.<level>`, bundling permissions of the type.
|
|
652
|
-
*/
|
|
653
|
-
interface AuthzRoleDeclaration {
|
|
654
|
-
/** The role's id, `<type>.<level>` with a lowercase identifier as the level. */
|
|
655
|
-
id: string;
|
|
656
|
-
/** The short names of the type's permissions the role bundles, such as `can_generate`. */
|
|
657
|
-
permissions: string[];
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* What a service declares about the resource its functions act on, as {@link AuthzResource} declares it.
|
|
661
|
-
*/
|
|
662
|
-
interface AuthzResourceDeclaration {
|
|
663
|
-
/** The resource type, a lowercase identifier such as `report`. */
|
|
664
|
-
value: string;
|
|
665
|
-
/** The type the resource sits under, such as `tenant` or `application`; absent for a root type. */
|
|
666
|
-
parent?: string | null;
|
|
667
|
-
/** The id template every function is checked on, such as `{@applicationId}`, when the service acts on one object. */
|
|
668
|
-
objectId?: string | null;
|
|
669
|
-
/** The permission every function of the service needs, when they all need the same one. */
|
|
670
|
-
permission?: string | null;
|
|
671
|
-
/** The roles the service declares for its type. */
|
|
672
|
-
roles?: AuthzRoleDeclaration[] | null;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* What a function declares about its check, as {@link AuthzCheck} declares it; whatever is left out is derived
|
|
676
|
-
* from the function's name and parameters.
|
|
677
|
-
*/
|
|
678
|
-
interface AuthzCheckDeclaration {
|
|
679
|
-
/** The short permission name, such as `can_generate`. */
|
|
680
|
-
permission?: string | null;
|
|
681
|
-
/** The type of the object the check is made on, when it is not the service's own. */
|
|
682
|
-
resource?: string | null;
|
|
683
|
-
/** The id template of the object, over the function's parameters and the caller's scope, such as `{reportId}`. */
|
|
684
|
-
objectId?: string | null;
|
|
685
|
-
/** Short names of permissions this one implies. */
|
|
686
|
-
implies?: string[] | null;
|
|
687
|
-
/** True for a function any caller the zone admits may call, which carries no check. */
|
|
688
|
-
zoneOnly?: boolean;
|
|
689
|
-
/** True for a check that must answer from the stored relationships rather than the engine's caches. */
|
|
690
|
-
consistent?: boolean;
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* One function of a service's contract: its name, the names of the parameters a request carries, in order,
|
|
694
|
-
* and what it declares about its check.
|
|
695
|
-
*/
|
|
696
|
-
interface FunctionContract {
|
|
697
|
-
name: string;
|
|
698
|
-
parameters: string[];
|
|
699
|
-
check?: AuthzCheckDeclaration | null;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* The contract of a service a runtime publishes, as the platform's directory stores it: where the service is
|
|
703
|
-
* addressed, the resource it declares and its functions. The platform derives each function's check from it,
|
|
704
|
-
* generates the application's authorization model with it, and checks every request to the service against it.
|
|
705
|
-
*/
|
|
706
|
-
interface ServiceContract {
|
|
707
|
-
namespace: string | null;
|
|
708
|
-
name: string;
|
|
709
|
-
version: string | null;
|
|
710
|
-
zone: string;
|
|
711
|
-
resource: AuthzResourceDeclaration;
|
|
712
|
-
functions: FunctionContract[];
|
|
713
|
-
}
|
|
650
|
+
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
714
651
|
/**
|
|
715
652
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
716
653
|
*/
|
|
@@ -723,10 +660,21 @@ declare class JsonEventFactory implements IEventFactory {
|
|
|
723
660
|
declare class TextEventFactory implements IEventFactory {
|
|
724
661
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
725
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Declares the definitions of the project's published services, as `kinotic sync` generates them into the
|
|
665
|
+
* project's ServiceDefinitions module, so every registry registers each service in the platform's service
|
|
666
|
+
* directory with its definition when the service comes online. A definition declared again for a qualified
|
|
667
|
+
* name replaces the one held.
|
|
668
|
+
* @param definitions the generated definitions
|
|
669
|
+
*/
|
|
670
|
+
declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
|
|
671
|
+
/**
|
|
672
|
+
* The default implementation of {@link IServiceRegistry}
|
|
673
|
+
*/
|
|
726
674
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
727
675
|
private _eventBus;
|
|
728
676
|
private supervisors;
|
|
729
|
-
private
|
|
677
|
+
private entries;
|
|
730
678
|
private contextInterceptor;
|
|
731
679
|
private debugLogger;
|
|
732
680
|
constructor(eventBus: IEventBus);
|
|
@@ -736,16 +684,13 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
736
684
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
737
685
|
unRegister(serviceIdentifier: ServiceIdentifier): void;
|
|
738
686
|
/**
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
* a service
|
|
742
|
-
|
|
743
|
-
publishContracts(): Promise<void>;
|
|
744
|
-
/**
|
|
745
|
-
* The contracts of the checked services registered, by the CRI each is registered under.
|
|
687
|
+
* Registers every application service registered so far in the platform's service directory, with the
|
|
688
|
+
* definition the project declared for it, so the directory lists the service and the platform checks
|
|
689
|
+
* requests to it; a service the platform refuses fails the registration. A service registered later is
|
|
690
|
+
* registered in the directory as it registers here.
|
|
746
691
|
*/
|
|
747
|
-
|
|
748
|
-
private
|
|
692
|
+
registerEntries(): Promise<void>;
|
|
693
|
+
private registerEntry;
|
|
749
694
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
750
695
|
}
|
|
751
696
|
/**
|
|
@@ -813,9 +758,9 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
813
758
|
get eventBus(): IEventBus;
|
|
814
759
|
set eventBus(eventBus: IEventBus);
|
|
815
760
|
/**
|
|
816
|
-
* Connects to a Kinotic server and
|
|
817
|
-
* Every option is optional: absent server fields and credentials resolve from the
|
|
818
|
-
* {@link ConnectOptions}.
|
|
761
|
+
* Connects to a Kinotic server and registers the application services registered so far in the platform's
|
|
762
|
+
* service directory. Every option is optional: absent server fields and credentials resolve from the
|
|
763
|
+
* environment — see {@link ConnectOptions}.
|
|
819
764
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
820
765
|
* @return Promise containing the result of the initial connection attempt
|
|
821
766
|
*/
|
|
@@ -843,6 +788,48 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
843
788
|
*/
|
|
844
789
|
declare const Kinotic: KinoticSingleton;
|
|
845
790
|
/**
|
|
791
|
+
* A role a service declares for its resource type, named `<type>.<level>`, bundling permissions of the type.
|
|
792
|
+
*/
|
|
793
|
+
interface AuthzRoleDeclaration {
|
|
794
|
+
/** The role's id, `<type>.<level>` with a lowercase identifier as the level. */
|
|
795
|
+
id: string;
|
|
796
|
+
/** The short names of the type's permissions the role bundles, such as `can_generate`. */
|
|
797
|
+
permissions: string[];
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* What a service declares about the resource its functions act on, as {@link AuthzResource} declares it.
|
|
801
|
+
*/
|
|
802
|
+
interface AuthzResourceDeclaration {
|
|
803
|
+
/** The resource type, a lowercase identifier such as `report`. */
|
|
804
|
+
value: string;
|
|
805
|
+
/** The type the resource sits under, such as `tenant` or `application`; absent for a root type. */
|
|
806
|
+
parent?: string | null;
|
|
807
|
+
/** The id template every function is checked on, such as `{@applicationId}`, when the service acts on one object. */
|
|
808
|
+
objectId?: string | null;
|
|
809
|
+
/** The permission every function of the service needs, when they all need the same one. */
|
|
810
|
+
permission?: string | null;
|
|
811
|
+
/** The roles the service declares for its type. */
|
|
812
|
+
roles?: AuthzRoleDeclaration[] | null;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* What a function declares about its check, as {@link AuthzCheck} declares it; whatever is left out is derived
|
|
816
|
+
* from the function's name and parameters.
|
|
817
|
+
*/
|
|
818
|
+
interface AuthzCheckDeclaration {
|
|
819
|
+
/** The short permission name, such as `can_generate`. */
|
|
820
|
+
permission?: string | null;
|
|
821
|
+
/** The type of the object the check is made on, when it is not the service's own. */
|
|
822
|
+
resource?: string | null;
|
|
823
|
+
/** The id template of the object, over the function's parameters and the caller's scope, such as `{reportId}`. */
|
|
824
|
+
objectId?: string | null;
|
|
825
|
+
/** Short names of permissions this one implies. */
|
|
826
|
+
implies?: string[] | null;
|
|
827
|
+
/** True for a function any caller the zone admits may call, which carries no check. */
|
|
828
|
+
zoneOnly?: boolean;
|
|
829
|
+
/** True for a check that must answer from the stored relationships rather than the engine's caches. */
|
|
830
|
+
consistent?: boolean;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
846
833
|
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
847
834
|
* specific instance of the service, such as the copy running on a particular node. It is
|
|
848
835
|
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
@@ -894,33 +881,30 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
894
881
|
*/
|
|
895
882
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
896
883
|
/**
|
|
897
|
-
* Declares the resource a service's functions act on
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
* `
|
|
902
|
-
*
|
|
903
|
-
*
|
|
884
|
+
* Declares the resource a service's functions act on. `kinotic sync` reads the declaration from the class's
|
|
885
|
+
* source into the service's definition, which the runtime registers in the platform's service directory when
|
|
886
|
+
* the service comes online, so every request to the service is checked. The check of each function is derived
|
|
887
|
+
* by the platform from the function's name and parameters, as it is for the platform's own services: a `find`,
|
|
888
|
+
* `get`, `count`, `search` or `list` function needs `can_view`, a `save`, `update` or `set` function `can_edit`,
|
|
889
|
+
* a `delete` or `remove` function `can_delete`, and a `create` function `can_edit` on the parent, each on the
|
|
890
|
+
* object a parameter named `id` or `<type>Id` names, or on the parent when none does. A function the derivation
|
|
891
|
+
* cannot read declares its check with {@link AuthzCheck}. A runtime holding no definition for a service
|
|
892
|
+
* declaring a resource refuses to serve it.
|
|
904
893
|
* @param declaration the resource type, or the type with its parent, object, permission and roles
|
|
905
894
|
*/
|
|
906
895
|
declare function AuthzResource(declaration: AuthzResourceDeclaration | string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
907
896
|
/**
|
|
908
|
-
* Declares the check of a function of an {@link AuthzResource} service
|
|
909
|
-
* `can_generate`, another object than the derived one,
|
|
910
|
-
* that any caller the zone admits may call it (`zoneOnly`).
|
|
897
|
+
* Declares the check of a function of an {@link AuthzResource} service, which `kinotic sync` reads into the
|
|
898
|
+
* service's definition: a permission of its own, such as `can_generate`, another object than the derived one,
|
|
899
|
+
* the permissions it implies, a consistent answer, or that any caller the zone admits may call it (`zoneOnly`).
|
|
911
900
|
* @param declaration what the derivation cannot read from the function's name and parameters
|
|
912
901
|
*/
|
|
913
|
-
declare function AuthzCheck(declaration: AuthzCheckDeclaration): (
|
|
902
|
+
declare function AuthzCheck(declaration: AuthzCheckDeclaration): (_value: Function, _context: ClassMethodDecoratorContext) => void;
|
|
914
903
|
/**
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
* parameters a request carries, read from the method's source, less the context a {@link Context} method
|
|
918
|
-
* takes last. A runtime whose build renames parameters publishes names a check's template cannot reference,
|
|
919
|
-
* which the platform refuses at registration.
|
|
920
|
-
* @param serviceInstance the registered instance
|
|
921
|
-
* @param serviceIdentifier how it is addressed, which the contract names
|
|
904
|
+
* Returns whether the given service instance's class, or a class it extends, declares an {@link AuthzResource}.
|
|
905
|
+
* @param serviceInstance the service instance to inspect
|
|
922
906
|
*/
|
|
923
|
-
declare function
|
|
907
|
+
declare function declaresAuthzResource(serviceInstance: object): boolean;
|
|
924
908
|
/**
|
|
925
909
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
926
910
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
@@ -931,6 +915,35 @@ declare function serviceContractOf(serviceInstance: object, serviceIdentifier: S
|
|
|
931
915
|
* so it appears in directory listings
|
|
932
916
|
*/
|
|
933
917
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
918
|
+
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
919
|
+
/**
|
|
920
|
+
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
921
|
+
* it belongs to, where it is addressed, whether it is advertised, and its definition with the decorators it
|
|
922
|
+
* declares. The platform owns everything else about the directory's entry: the checks it derives, the tools the
|
|
923
|
+
* functions declare, and the service's liveness.
|
|
924
|
+
*/
|
|
925
|
+
interface ServiceDirectoryEntry {
|
|
926
|
+
/**
|
|
927
|
+
* The application the service belongs to, which its zone names.
|
|
928
|
+
*/
|
|
929
|
+
applicationId: string;
|
|
930
|
+
/**
|
|
931
|
+
* The zone the service is addressed in, the application's or a label under it.
|
|
932
|
+
*/
|
|
933
|
+
zone: string;
|
|
934
|
+
/**
|
|
935
|
+
* The version the service registers under, or null for none.
|
|
936
|
+
*/
|
|
937
|
+
version: string | null;
|
|
938
|
+
/**
|
|
939
|
+
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
940
|
+
*/
|
|
941
|
+
advertised: boolean;
|
|
942
|
+
/**
|
|
943
|
+
* The service's definition: its functions, and the decorators it declares.
|
|
944
|
+
*/
|
|
945
|
+
serviceDefinition: ServiceDefinition2;
|
|
946
|
+
}
|
|
934
947
|
/**
|
|
935
948
|
* Validates that the given zone satisfies the zone grammar
|
|
936
949
|
* @param zone the zone to validate
|
|
@@ -1528,4 +1541,4 @@ declare class ParticipantConstants {
|
|
|
1528
1541
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1529
1542
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1530
1543
|
}
|
|
1531
|
-
export { validateZone, validateLabel,
|
|
1544
|
+
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declaresAuthzResource, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthzRoleDeclaration, AuthzResourceDeclaration, AuthzResource, AuthzCheckDeclaration, AuthzCheck, AuthorizationException, AbstractIterablePage };
|
package/dist/index.d.ts
CHANGED
|
@@ -647,70 +647,7 @@ interface IServiceRegistry {
|
|
|
647
647
|
*/
|
|
648
648
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
649
|
}
|
|
650
|
-
|
|
651
|
-
* A role a service declares for its resource type, named `<type>.<level>`, bundling permissions of the type.
|
|
652
|
-
*/
|
|
653
|
-
interface AuthzRoleDeclaration {
|
|
654
|
-
/** The role's id, `<type>.<level>` with a lowercase identifier as the level. */
|
|
655
|
-
id: string;
|
|
656
|
-
/** The short names of the type's permissions the role bundles, such as `can_generate`. */
|
|
657
|
-
permissions: string[];
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* What a service declares about the resource its functions act on, as {@link AuthzResource} declares it.
|
|
661
|
-
*/
|
|
662
|
-
interface AuthzResourceDeclaration {
|
|
663
|
-
/** The resource type, a lowercase identifier such as `report`. */
|
|
664
|
-
value: string;
|
|
665
|
-
/** The type the resource sits under, such as `tenant` or `application`; absent for a root type. */
|
|
666
|
-
parent?: string | null;
|
|
667
|
-
/** The id template every function is checked on, such as `{@applicationId}`, when the service acts on one object. */
|
|
668
|
-
objectId?: string | null;
|
|
669
|
-
/** The permission every function of the service needs, when they all need the same one. */
|
|
670
|
-
permission?: string | null;
|
|
671
|
-
/** The roles the service declares for its type. */
|
|
672
|
-
roles?: AuthzRoleDeclaration[] | null;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* What a function declares about its check, as {@link AuthzCheck} declares it; whatever is left out is derived
|
|
676
|
-
* from the function's name and parameters.
|
|
677
|
-
*/
|
|
678
|
-
interface AuthzCheckDeclaration {
|
|
679
|
-
/** The short permission name, such as `can_generate`. */
|
|
680
|
-
permission?: string | null;
|
|
681
|
-
/** The type of the object the check is made on, when it is not the service's own. */
|
|
682
|
-
resource?: string | null;
|
|
683
|
-
/** The id template of the object, over the function's parameters and the caller's scope, such as `{reportId}`. */
|
|
684
|
-
objectId?: string | null;
|
|
685
|
-
/** Short names of permissions this one implies. */
|
|
686
|
-
implies?: string[] | null;
|
|
687
|
-
/** True for a function any caller the zone admits may call, which carries no check. */
|
|
688
|
-
zoneOnly?: boolean;
|
|
689
|
-
/** True for a check that must answer from the stored relationships rather than the engine's caches. */
|
|
690
|
-
consistent?: boolean;
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* One function of a service's contract: its name, the names of the parameters a request carries, in order,
|
|
694
|
-
* and what it declares about its check.
|
|
695
|
-
*/
|
|
696
|
-
interface FunctionContract {
|
|
697
|
-
name: string;
|
|
698
|
-
parameters: string[];
|
|
699
|
-
check?: AuthzCheckDeclaration | null;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* The contract of a service a runtime publishes, as the platform's directory stores it: where the service is
|
|
703
|
-
* addressed, the resource it declares and its functions. The platform derives each function's check from it,
|
|
704
|
-
* generates the application's authorization model with it, and checks every request to the service against it.
|
|
705
|
-
*/
|
|
706
|
-
interface ServiceContract {
|
|
707
|
-
namespace: string | null;
|
|
708
|
-
name: string;
|
|
709
|
-
version: string | null;
|
|
710
|
-
zone: string;
|
|
711
|
-
resource: AuthzResourceDeclaration;
|
|
712
|
-
functions: FunctionContract[];
|
|
713
|
-
}
|
|
650
|
+
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
714
651
|
/**
|
|
715
652
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
716
653
|
*/
|
|
@@ -723,10 +660,21 @@ declare class JsonEventFactory implements IEventFactory {
|
|
|
723
660
|
declare class TextEventFactory implements IEventFactory {
|
|
724
661
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
725
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Declares the definitions of the project's published services, as `kinotic sync` generates them into the
|
|
665
|
+
* project's ServiceDefinitions module, so every registry registers each service in the platform's service
|
|
666
|
+
* directory with its definition when the service comes online. A definition declared again for a qualified
|
|
667
|
+
* name replaces the one held.
|
|
668
|
+
* @param definitions the generated definitions
|
|
669
|
+
*/
|
|
670
|
+
declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
|
|
671
|
+
/**
|
|
672
|
+
* The default implementation of {@link IServiceRegistry}
|
|
673
|
+
*/
|
|
726
674
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
727
675
|
private _eventBus;
|
|
728
676
|
private supervisors;
|
|
729
|
-
private
|
|
677
|
+
private entries;
|
|
730
678
|
private contextInterceptor;
|
|
731
679
|
private debugLogger;
|
|
732
680
|
constructor(eventBus: IEventBus);
|
|
@@ -736,16 +684,13 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
736
684
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
737
685
|
unRegister(serviceIdentifier: ServiceIdentifier): void;
|
|
738
686
|
/**
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
* a service
|
|
742
|
-
|
|
743
|
-
publishContracts(): Promise<void>;
|
|
744
|
-
/**
|
|
745
|
-
* The contracts of the checked services registered, by the CRI each is registered under.
|
|
687
|
+
* Registers every application service registered so far in the platform's service directory, with the
|
|
688
|
+
* definition the project declared for it, so the directory lists the service and the platform checks
|
|
689
|
+
* requests to it; a service the platform refuses fails the registration. A service registered later is
|
|
690
|
+
* registered in the directory as it registers here.
|
|
746
691
|
*/
|
|
747
|
-
|
|
748
|
-
private
|
|
692
|
+
registerEntries(): Promise<void>;
|
|
693
|
+
private registerEntry;
|
|
749
694
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
750
695
|
}
|
|
751
696
|
/**
|
|
@@ -813,9 +758,9 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
813
758
|
get eventBus(): IEventBus;
|
|
814
759
|
set eventBus(eventBus: IEventBus);
|
|
815
760
|
/**
|
|
816
|
-
* Connects to a Kinotic server and
|
|
817
|
-
* Every option is optional: absent server fields and credentials resolve from the
|
|
818
|
-
* {@link ConnectOptions}.
|
|
761
|
+
* Connects to a Kinotic server and registers the application services registered so far in the platform's
|
|
762
|
+
* service directory. Every option is optional: absent server fields and credentials resolve from the
|
|
763
|
+
* environment — see {@link ConnectOptions}.
|
|
819
764
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
820
765
|
* @return Promise containing the result of the initial connection attempt
|
|
821
766
|
*/
|
|
@@ -843,6 +788,48 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
843
788
|
*/
|
|
844
789
|
declare const Kinotic: KinoticSingleton;
|
|
845
790
|
/**
|
|
791
|
+
* A role a service declares for its resource type, named `<type>.<level>`, bundling permissions of the type.
|
|
792
|
+
*/
|
|
793
|
+
interface AuthzRoleDeclaration {
|
|
794
|
+
/** The role's id, `<type>.<level>` with a lowercase identifier as the level. */
|
|
795
|
+
id: string;
|
|
796
|
+
/** The short names of the type's permissions the role bundles, such as `can_generate`. */
|
|
797
|
+
permissions: string[];
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* What a service declares about the resource its functions act on, as {@link AuthzResource} declares it.
|
|
801
|
+
*/
|
|
802
|
+
interface AuthzResourceDeclaration {
|
|
803
|
+
/** The resource type, a lowercase identifier such as `report`. */
|
|
804
|
+
value: string;
|
|
805
|
+
/** The type the resource sits under, such as `tenant` or `application`; absent for a root type. */
|
|
806
|
+
parent?: string | null;
|
|
807
|
+
/** The id template every function is checked on, such as `{@applicationId}`, when the service acts on one object. */
|
|
808
|
+
objectId?: string | null;
|
|
809
|
+
/** The permission every function of the service needs, when they all need the same one. */
|
|
810
|
+
permission?: string | null;
|
|
811
|
+
/** The roles the service declares for its type. */
|
|
812
|
+
roles?: AuthzRoleDeclaration[] | null;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* What a function declares about its check, as {@link AuthzCheck} declares it; whatever is left out is derived
|
|
816
|
+
* from the function's name and parameters.
|
|
817
|
+
*/
|
|
818
|
+
interface AuthzCheckDeclaration {
|
|
819
|
+
/** The short permission name, such as `can_generate`. */
|
|
820
|
+
permission?: string | null;
|
|
821
|
+
/** The type of the object the check is made on, when it is not the service's own. */
|
|
822
|
+
resource?: string | null;
|
|
823
|
+
/** The id template of the object, over the function's parameters and the caller's scope, such as `{reportId}`. */
|
|
824
|
+
objectId?: string | null;
|
|
825
|
+
/** Short names of permissions this one implies. */
|
|
826
|
+
implies?: string[] | null;
|
|
827
|
+
/** True for a function any caller the zone admits may call, which carries no check. */
|
|
828
|
+
zoneOnly?: boolean;
|
|
829
|
+
/** True for a check that must answer from the stored relationships rather than the engine's caches. */
|
|
830
|
+
consistent?: boolean;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
846
833
|
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
847
834
|
* specific instance of the service, such as the copy running on a particular node. It is
|
|
848
835
|
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
@@ -894,33 +881,30 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
894
881
|
*/
|
|
895
882
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
896
883
|
/**
|
|
897
|
-
* Declares the resource a service's functions act on
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
* `
|
|
902
|
-
*
|
|
903
|
-
*
|
|
884
|
+
* Declares the resource a service's functions act on. `kinotic sync` reads the declaration from the class's
|
|
885
|
+
* source into the service's definition, which the runtime registers in the platform's service directory when
|
|
886
|
+
* the service comes online, so every request to the service is checked. The check of each function is derived
|
|
887
|
+
* by the platform from the function's name and parameters, as it is for the platform's own services: a `find`,
|
|
888
|
+
* `get`, `count`, `search` or `list` function needs `can_view`, a `save`, `update` or `set` function `can_edit`,
|
|
889
|
+
* a `delete` or `remove` function `can_delete`, and a `create` function `can_edit` on the parent, each on the
|
|
890
|
+
* object a parameter named `id` or `<type>Id` names, or on the parent when none does. A function the derivation
|
|
891
|
+
* cannot read declares its check with {@link AuthzCheck}. A runtime holding no definition for a service
|
|
892
|
+
* declaring a resource refuses to serve it.
|
|
904
893
|
* @param declaration the resource type, or the type with its parent, object, permission and roles
|
|
905
894
|
*/
|
|
906
895
|
declare function AuthzResource(declaration: AuthzResourceDeclaration | string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
907
896
|
/**
|
|
908
|
-
* Declares the check of a function of an {@link AuthzResource} service
|
|
909
|
-
* `can_generate`, another object than the derived one,
|
|
910
|
-
* that any caller the zone admits may call it (`zoneOnly`).
|
|
897
|
+
* Declares the check of a function of an {@link AuthzResource} service, which `kinotic sync` reads into the
|
|
898
|
+
* service's definition: a permission of its own, such as `can_generate`, another object than the derived one,
|
|
899
|
+
* the permissions it implies, a consistent answer, or that any caller the zone admits may call it (`zoneOnly`).
|
|
911
900
|
* @param declaration what the derivation cannot read from the function's name and parameters
|
|
912
901
|
*/
|
|
913
|
-
declare function AuthzCheck(declaration: AuthzCheckDeclaration): (
|
|
902
|
+
declare function AuthzCheck(declaration: AuthzCheckDeclaration): (_value: Function, _context: ClassMethodDecoratorContext) => void;
|
|
914
903
|
/**
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
* parameters a request carries, read from the method's source, less the context a {@link Context} method
|
|
918
|
-
* takes last. A runtime whose build renames parameters publishes names a check's template cannot reference,
|
|
919
|
-
* which the platform refuses at registration.
|
|
920
|
-
* @param serviceInstance the registered instance
|
|
921
|
-
* @param serviceIdentifier how it is addressed, which the contract names
|
|
904
|
+
* Returns whether the given service instance's class, or a class it extends, declares an {@link AuthzResource}.
|
|
905
|
+
* @param serviceInstance the service instance to inspect
|
|
922
906
|
*/
|
|
923
|
-
declare function
|
|
907
|
+
declare function declaresAuthzResource(serviceInstance: object): boolean;
|
|
924
908
|
/**
|
|
925
909
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
926
910
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
@@ -931,6 +915,35 @@ declare function serviceContractOf(serviceInstance: object, serviceIdentifier: S
|
|
|
931
915
|
* so it appears in directory listings
|
|
932
916
|
*/
|
|
933
917
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
918
|
+
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
919
|
+
/**
|
|
920
|
+
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
921
|
+
* it belongs to, where it is addressed, whether it is advertised, and its definition with the decorators it
|
|
922
|
+
* declares. The platform owns everything else about the directory's entry: the checks it derives, the tools the
|
|
923
|
+
* functions declare, and the service's liveness.
|
|
924
|
+
*/
|
|
925
|
+
interface ServiceDirectoryEntry {
|
|
926
|
+
/**
|
|
927
|
+
* The application the service belongs to, which its zone names.
|
|
928
|
+
*/
|
|
929
|
+
applicationId: string;
|
|
930
|
+
/**
|
|
931
|
+
* The zone the service is addressed in, the application's or a label under it.
|
|
932
|
+
*/
|
|
933
|
+
zone: string;
|
|
934
|
+
/**
|
|
935
|
+
* The version the service registers under, or null for none.
|
|
936
|
+
*/
|
|
937
|
+
version: string | null;
|
|
938
|
+
/**
|
|
939
|
+
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
940
|
+
*/
|
|
941
|
+
advertised: boolean;
|
|
942
|
+
/**
|
|
943
|
+
* The service's definition: its functions, and the decorators it declares.
|
|
944
|
+
*/
|
|
945
|
+
serviceDefinition: ServiceDefinition2;
|
|
946
|
+
}
|
|
934
947
|
/**
|
|
935
948
|
* Validates that the given zone satisfies the zone grammar
|
|
936
949
|
* @param zone the zone to validate
|
|
@@ -1528,4 +1541,4 @@ declare class ParticipantConstants {
|
|
|
1528
1541
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1529
1542
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1530
1543
|
}
|
|
1531
|
-
export { validateZone, validateLabel,
|
|
1544
|
+
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declaresAuthzResource, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthzRoleDeclaration, AuthzResourceDeclaration, AuthzResource, AuthzCheckDeclaration, AuthzCheck, AuthorizationException, AbstractIterablePage };
|
package/dist/index.js
CHANGED
|
@@ -1064,8 +1064,7 @@ var versionRegistry = new WeakMap;
|
|
|
1064
1064
|
var zonesRegistry = new WeakMap;
|
|
1065
1065
|
var advertisedRegistry = new WeakMap;
|
|
1066
1066
|
var contextMarkedFunctions = new WeakSet;
|
|
1067
|
-
var
|
|
1068
|
-
var authzCheckRegistry = new WeakMap;
|
|
1067
|
+
var authzResourceClasses = new WeakSet;
|
|
1069
1068
|
function findInConstructorChain(registry, constructor) {
|
|
1070
1069
|
let current = constructor;
|
|
1071
1070
|
while (current) {
|
|
@@ -1157,97 +1156,19 @@ function resolveEffectiveZone(constructor) {
|
|
|
1157
1156
|
return effectiveZone;
|
|
1158
1157
|
}
|
|
1159
1158
|
function AuthzResource(declaration) {
|
|
1160
|
-
const resource = typeof declaration === "string" ? { value: declaration } : declaration;
|
|
1161
|
-
if (!resource.value) {
|
|
1162
|
-
throw new Error("AuthzResource must name the resource type");
|
|
1163
|
-
}
|
|
1164
1159
|
return function(value, _context) {
|
|
1165
|
-
|
|
1160
|
+
authzResourceClasses.add(value);
|
|
1166
1161
|
};
|
|
1167
1162
|
}
|
|
1168
1163
|
function AuthzCheck(declaration) {
|
|
1169
|
-
return function(
|
|
1170
|
-
authzCheckRegistry.set(value, declaration);
|
|
1171
|
-
};
|
|
1164
|
+
return function(_value, _context) {};
|
|
1172
1165
|
}
|
|
1173
|
-
function
|
|
1174
|
-
|
|
1175
|
-
let
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
}
|
|
1180
|
-
const functions = [];
|
|
1181
|
-
const seen = new Set;
|
|
1182
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1183
|
-
while (proto && proto !== Object.prototype) {
|
|
1184
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1185
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1186
|
-
if (typeof descriptor?.value === "function" && key !== "constructor" && !seen.has(key)) {
|
|
1187
|
-
seen.add(key);
|
|
1188
|
-
const method = descriptor.value;
|
|
1189
|
-
const parameters = parameterNames(method);
|
|
1190
|
-
if (contextMarkedFunctions.has(method)) {
|
|
1191
|
-
parameters.pop();
|
|
1192
|
-
}
|
|
1193
|
-
functions.push({ name: key, parameters, check: authzCheckRegistry.get(method) ?? null });
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
proto = Object.getPrototypeOf(proto);
|
|
1197
|
-
}
|
|
1198
|
-
ret = {
|
|
1199
|
-
namespace: serviceIdentifier.namespace,
|
|
1200
|
-
name: serviceIdentifier.name,
|
|
1201
|
-
version: serviceIdentifier.version ?? null,
|
|
1202
|
-
zone: serviceIdentifier.zone,
|
|
1203
|
-
resource,
|
|
1204
|
-
functions
|
|
1205
|
-
};
|
|
1206
|
-
}
|
|
1207
|
-
return ret;
|
|
1208
|
-
}
|
|
1209
|
-
function parameterNames(method) {
|
|
1210
|
-
const source = method.toString().replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1211
|
-
let depth = 0;
|
|
1212
|
-
let start = -1;
|
|
1213
|
-
let end = -1;
|
|
1214
|
-
for (let i = 0;i < source.length && end < 0; i++) {
|
|
1215
|
-
const c = source[i];
|
|
1216
|
-
if (c === "(") {
|
|
1217
|
-
if (depth === 0 && start < 0) {
|
|
1218
|
-
start = i + 1;
|
|
1219
|
-
}
|
|
1220
|
-
depth++;
|
|
1221
|
-
} else if (c === ")") {
|
|
1222
|
-
depth--;
|
|
1223
|
-
if (depth === 0 && start >= 0) {
|
|
1224
|
-
end = i;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
const ret = [];
|
|
1229
|
-
if (start >= 0 && end >= 0) {
|
|
1230
|
-
let nested = 0;
|
|
1231
|
-
let current = "";
|
|
1232
|
-
const parts = [];
|
|
1233
|
-
for (const c of source.substring(start, end)) {
|
|
1234
|
-
if ("([{".includes(c)) {
|
|
1235
|
-
nested++;
|
|
1236
|
-
} else if (")]}".includes(c)) {
|
|
1237
|
-
nested--;
|
|
1238
|
-
}
|
|
1239
|
-
if (c === "," && nested === 0) {
|
|
1240
|
-
parts.push(current);
|
|
1241
|
-
current = "";
|
|
1242
|
-
} else {
|
|
1243
|
-
current += c;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
parts.push(current);
|
|
1247
|
-
parts.map((part) => (part.split("=")[0] ?? "").trim()).filter((part) => part.length > 0).forEach((part, index) => {
|
|
1248
|
-
const name = part.replace(/^\.\.\./, "");
|
|
1249
|
-
ret.push(/^[A-Za-z_$][\w$]*$/.test(name) ? name : `arg${index}`);
|
|
1250
|
-
});
|
|
1166
|
+
function declaresAuthzResource(serviceInstance) {
|
|
1167
|
+
let ret = false;
|
|
1168
|
+
let current = serviceInstance.constructor;
|
|
1169
|
+
while (current && !ret) {
|
|
1170
|
+
ret = authzResourceClasses.has(current);
|
|
1171
|
+
current = Object.getPrototypeOf(current);
|
|
1251
1172
|
}
|
|
1252
1173
|
return ret;
|
|
1253
1174
|
}
|
|
@@ -1278,7 +1199,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
|
|
|
1278
1199
|
// packages/core/package.json
|
|
1279
1200
|
var package_default = {
|
|
1280
1201
|
name: "@kinotic-ai/core",
|
|
1281
|
-
version: "5.0.0-beta.
|
|
1202
|
+
version: "5.0.0-beta.20",
|
|
1282
1203
|
type: "module",
|
|
1283
1204
|
files: [
|
|
1284
1205
|
"dist"
|
|
@@ -1347,6 +1268,7 @@ var package_default = {
|
|
|
1347
1268
|
vitest: "^4.1.4"
|
|
1348
1269
|
},
|
|
1349
1270
|
dependencies: {
|
|
1271
|
+
"@kinotic-ai/idl": "workspace:*",
|
|
1350
1272
|
"@opentelemetry/api": "^1.9.1",
|
|
1351
1273
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1352
1274
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1740,13 +1662,61 @@ class TextEventFactory {
|
|
|
1740
1662
|
return event;
|
|
1741
1663
|
}
|
|
1742
1664
|
}
|
|
1743
|
-
var
|
|
1665
|
+
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1744
1666
|
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1667
|
+
var declaredDefinitions = new Map;
|
|
1668
|
+
function declareServiceDefinitions(definitions) {
|
|
1669
|
+
for (const definition of definitions) {
|
|
1670
|
+
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
function qualifiedNameOf(namespace, name) {
|
|
1674
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
1675
|
+
}
|
|
1676
|
+
function servedFunctions(serviceInstance) {
|
|
1677
|
+
const ret = new Set;
|
|
1678
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1679
|
+
while (proto && proto !== Object.prototype) {
|
|
1680
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1681
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1682
|
+
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1683
|
+
ret.add(key);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
proto = Object.getPrototypeOf(proto);
|
|
1687
|
+
}
|
|
1688
|
+
return [...ret].sort();
|
|
1689
|
+
}
|
|
1690
|
+
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1691
|
+
let ret = null;
|
|
1692
|
+
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1693
|
+
if (application) {
|
|
1694
|
+
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1695
|
+
const definition = declaredDefinitions.get(qualifiedName);
|
|
1696
|
+
if (definition) {
|
|
1697
|
+
const declared = definition.functions.map((f) => f.name).sort();
|
|
1698
|
+
const served = servedFunctions(serviceInstance);
|
|
1699
|
+
if (declared.join() !== served.join()) {
|
|
1700
|
+
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1701
|
+
}
|
|
1702
|
+
ret = {
|
|
1703
|
+
applicationId: application[1],
|
|
1704
|
+
zone: serviceIdentifier.zone,
|
|
1705
|
+
version: serviceIdentifier.version ?? null,
|
|
1706
|
+
advertised: isAdvertised(serviceInstance),
|
|
1707
|
+
serviceDefinition: definition
|
|
1708
|
+
};
|
|
1709
|
+
} else if (declaresAuthzResource(serviceInstance)) {
|
|
1710
|
+
throw new Error(`${qualifiedName} declares a resource but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
return ret;
|
|
1714
|
+
}
|
|
1745
1715
|
|
|
1746
1716
|
class ServiceRegistry {
|
|
1747
1717
|
_eventBus;
|
|
1748
1718
|
supervisors = new Map;
|
|
1749
|
-
|
|
1719
|
+
entries = new Map;
|
|
1750
1720
|
contextInterceptor = null;
|
|
1751
1721
|
debugLogger = debug3("kinotic:serviceRegistry");
|
|
1752
1722
|
constructor(eventBus) {
|
|
@@ -1768,14 +1738,14 @@ class ServiceRegistry {
|
|
|
1768
1738
|
const criString = serviceIdentifier.cri().raw();
|
|
1769
1739
|
if (!this.supervisors.has(criString)) {
|
|
1770
1740
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1771
|
-
const
|
|
1741
|
+
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1772
1742
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1773
1743
|
this.supervisors.set(criString, supervisor);
|
|
1774
1744
|
supervisor.start();
|
|
1775
|
-
if (
|
|
1776
|
-
this.
|
|
1745
|
+
if (entry) {
|
|
1746
|
+
this.entries.set(criString, entry);
|
|
1777
1747
|
if (this.eventBus.isConnected()) {
|
|
1778
|
-
this.
|
|
1748
|
+
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1779
1749
|
}
|
|
1780
1750
|
}
|
|
1781
1751
|
}
|
|
@@ -1787,23 +1757,17 @@ class ServiceRegistry {
|
|
|
1787
1757
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1788
1758
|
supervisor.stop();
|
|
1789
1759
|
this.supervisors.delete(criString);
|
|
1790
|
-
this.
|
|
1760
|
+
this.entries.delete(criString);
|
|
1791
1761
|
}
|
|
1792
1762
|
}
|
|
1793
|
-
async
|
|
1794
|
-
for (const
|
|
1795
|
-
await this.
|
|
1763
|
+
async registerEntries() {
|
|
1764
|
+
for (const entry of this.entries.values()) {
|
|
1765
|
+
await this.registerEntry(entry);
|
|
1796
1766
|
}
|
|
1797
1767
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
async publishContract(contract) {
|
|
1802
|
-
const application = APPLICATION_ZONE.exec(contract.zone);
|
|
1803
|
-
if (application) {
|
|
1804
|
-
this.debugLogger(`Publishing the contract of ${contract.zone}~${contract.namespace}.${contract.name}`);
|
|
1805
|
-
await this.serviceProxy(SERVICE_CONTRACT_SERVICE).invoke("register", [application[1], contract]);
|
|
1806
|
-
}
|
|
1768
|
+
async registerEntry(entry) {
|
|
1769
|
+
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1770
|
+
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1807
1771
|
}
|
|
1808
1772
|
registerContextInterceptor(interceptor) {
|
|
1809
1773
|
this.contextInterceptor = interceptor;
|
|
@@ -1898,7 +1862,7 @@ class KinoticSingleton {
|
|
|
1898
1862
|
}
|
|
1899
1863
|
async connect(options) {
|
|
1900
1864
|
const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1901
|
-
await this.serviceRegistry.
|
|
1865
|
+
await this.serviceRegistry.registerEntries();
|
|
1902
1866
|
return ret;
|
|
1903
1867
|
}
|
|
1904
1868
|
disconnect(force) {
|
|
@@ -2168,10 +2132,11 @@ class ParticipantConstants {
|
|
|
2168
2132
|
export {
|
|
2169
2133
|
validateZone,
|
|
2170
2134
|
validateLabel,
|
|
2171
|
-
serviceContractOf,
|
|
2172
2135
|
scopeOptionalMethodNames,
|
|
2173
2136
|
receivesContext,
|
|
2174
2137
|
isAdvertised,
|
|
2138
|
+
declaresAuthzResource,
|
|
2139
|
+
declareServiceDefinitions,
|
|
2175
2140
|
createCRI,
|
|
2176
2141
|
buildServerUrl,
|
|
2177
2142
|
buildBrokerUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"vitest": "^4.1.4"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
+
"@kinotic-ai/idl": "5.0.0-beta.2",
|
|
72
73
|
"@opentelemetry/api": "^1.9.1",
|
|
73
74
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
74
75
|
"@stomp/rx-stomp": "^2.4.0",
|