MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / handleRequest

Method handleRequest

packages/server/src/api/rest/index.ts:448–665  ·  view source on GitHub ↗
({ client, method, path, query, requestBody }: RequestContext<Schema>)

Source from the content-addressed store, hash-verified

446 }
447
448 async handleRequest({ client, method, path, query, requestBody }: RequestContext<Schema>): Promise<Response> {
449 method = method.toUpperCase();
450 if (!path.startsWith('/')) {
451 path = '/' + path;
452 }
453
454 try {
455 if (path.startsWith('/$procs/')) {
456 const proc = path.split('/')[2];
457 return await this.processProcedureRequest({ client, method, proc, query, requestBody });
458 }
459
460 switch (method) {
461 case 'GET': {
462 let match = this.matchUrlPattern(path, UrlPatterns.SINGLE);
463 if (match) {
464 // single resource read
465 return await this.processSingleRead(client, match.type, match.id, query);
466 }
467 match = this.matchUrlPattern(path, UrlPatterns.FETCH_RELATIONSHIP);
468 if (match) {
469 // fetch related resource(s)
470 return await this.processFetchRelated(client, match.type, match.id, match.relationship, query);
471 }
472
473 match = this.matchUrlPattern(path, UrlPatterns.RELATIONSHIP);
474 if (match) {
475 // read relationship
476 return await this.processReadRelationship(
477 client,
478 match.type,
479 match.id,
480 match.relationship,
481 query,
482 );
483 }
484
485 // /:type/:id/:relationship/:childId — nested single read
486 match = this.matchUrlPattern(path, UrlPatterns.NESTED_SINGLE);
487 if (match && this.nestedRoutes && this.resolveNestedRelation(match.type, match.relationship)?.isCollection) {
488 return await this.processNestedSingleRead(
489 client,
490 match.type,
491 match.id,
492 match.relationship,
493 match.childId!,
494 query,
495 );
496 }
497 match = this.matchUrlPattern(path, UrlPatterns.COLLECTION);
498 if (match) {
499 // collection read
500 return await this.processCollectionRead(client, match.type, query);
501 }
502
503 return this.makeError('invalidPath');
504 }
505

Callers

nothing calls this directly

Calls 15

matchUrlPatternMethod · 0.95
processSingleReadMethod · 0.95
processFetchRelatedMethod · 0.95
resolveNestedRelationMethod · 0.95
processCollectionReadMethod · 0.95
makeErrorMethod · 0.95
processNestedCreateMethod · 0.95
processUpsertMethod · 0.95
processCreateMethod · 0.95

Tested by

no test coverage detected