2020-11-03 10:49:48 +08:00
|
|
|
/**
|
2022-10-18 23:19:24 +08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2020-11-03 10:49:48 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type {JSONValue, ResponseBase} from 'react-client/src/ReactFlightClient';
|
|
|
|
|
|
2022-05-07 02:24:04 +08:00
|
|
|
import type {JSResourceReference} from 'JSResourceReference';
|
2020-11-03 10:49:48 +08:00
|
|
|
|
2023-02-10 08:45:05 +08:00
|
|
|
import type {ClientReferenceMetadata} from 'ReactFlightNativeRelayClientIntegration';
|
2022-05-28 04:16:24 +08:00
|
|
|
|
2023-01-28 09:08:26 +08:00
|
|
|
export type ClientReference<T> = JSResourceReference<T>;
|
2020-11-03 10:49:48 +08:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
parseModelString,
|
|
|
|
|
parseModelTuple,
|
|
|
|
|
} from 'react-client/src/ReactFlightClient';
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
preloadModule,
|
|
|
|
|
requireModule,
|
|
|
|
|
} from 'ReactFlightNativeRelayClientIntegration';
|
|
|
|
|
|
2023-01-28 09:08:26 +08:00
|
|
|
import {resolveClientReference as resolveClientReferenceImpl} from 'ReactFlightNativeRelayClientIntegration';
|
2022-05-28 04:16:24 +08:00
|
|
|
|
2021-04-07 22:57:43 +08:00
|
|
|
import isArray from 'shared/isArray';
|
|
|
|
|
|
2023-02-10 08:45:05 +08:00
|
|
|
export type {ClientReferenceMetadata} from 'ReactFlightNativeRelayClientIntegration';
|
2020-11-03 10:49:48 +08:00
|
|
|
|
2023-03-09 12:45:55 +08:00
|
|
|
export type SSRManifest = null;
|
2023-03-11 00:36:15 +08:00
|
|
|
export type ServerManifest = null;
|
|
|
|
|
export type ServerReferenceId = string;
|
2022-05-28 04:16:24 +08:00
|
|
|
|
2020-11-11 11:54:42 +08:00
|
|
|
export type UninitializedModel = JSONValue;
|
2020-11-03 10:49:48 +08:00
|
|
|
|
|
|
|
|
export type Response = ResponseBase;
|
|
|
|
|
|
2023-01-28 09:08:26 +08:00
|
|
|
export function resolveClientReference<T>(
|
2023-03-09 12:45:55 +08:00
|
|
|
bundlerConfig: SSRManifest,
|
2023-02-10 08:45:05 +08:00
|
|
|
metadata: ClientReferenceMetadata,
|
2023-01-28 09:08:26 +08:00
|
|
|
): ClientReference<T> {
|
2023-02-10 08:45:05 +08:00
|
|
|
return resolveClientReferenceImpl(metadata);
|
2022-05-28 04:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-11 00:36:15 +08:00
|
|
|
export function resolveServerReference<T>(
|
|
|
|
|
bundlerConfig: ServerManifest,
|
|
|
|
|
id: ServerReferenceId,
|
|
|
|
|
): ClientReference<T> {
|
|
|
|
|
throw new Error('Not implemented.');
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 06:07:39 +08:00
|
|
|
function parseModelRecursively(
|
|
|
|
|
response: Response,
|
|
|
|
|
parentObj: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
|
|
|
|
|
key: string,
|
|
|
|
|
value: JSONValue,
|
|
|
|
|
): $FlowFixMe {
|
2020-11-03 10:49:48 +08:00
|
|
|
if (typeof value === 'string') {
|
2022-09-15 08:13:33 +08:00
|
|
|
return parseModelString(response, parentObj, key, value);
|
2020-11-03 10:49:48 +08:00
|
|
|
}
|
|
|
|
|
if (typeof value === 'object' && value !== null) {
|
2021-04-07 22:57:43 +08:00
|
|
|
if (isArray(value)) {
|
2023-02-10 06:07:39 +08:00
|
|
|
const parsedValue: Array<$FlowFixMe> = [];
|
2020-11-03 10:49:48 +08:00
|
|
|
for (let i = 0; i < value.length; i++) {
|
2020-12-17 03:53:51 +08:00
|
|
|
(parsedValue: any)[i] = parseModelRecursively(
|
|
|
|
|
response,
|
|
|
|
|
value,
|
2022-09-15 08:13:33 +08:00
|
|
|
'' + i,
|
2020-12-17 03:53:51 +08:00
|
|
|
value[i],
|
|
|
|
|
);
|
2020-11-03 10:49:48 +08:00
|
|
|
}
|
2020-12-17 03:53:51 +08:00
|
|
|
return parseModelTuple(response, parsedValue);
|
2020-11-03 10:49:48 +08:00
|
|
|
} else {
|
2020-12-17 03:53:51 +08:00
|
|
|
const parsedValue = {};
|
2020-11-03 10:49:48 +08:00
|
|
|
for (const innerKey in value) {
|
2020-12-17 03:53:51 +08:00
|
|
|
(parsedValue: any)[innerKey] = parseModelRecursively(
|
2020-11-03 10:49:48 +08:00
|
|
|
response,
|
|
|
|
|
value,
|
2022-09-15 08:13:33 +08:00
|
|
|
innerKey,
|
2020-11-03 10:49:48 +08:00
|
|
|
value[innerKey],
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-12-17 03:53:51 +08:00
|
|
|
return parsedValue;
|
2020-11-03 10:49:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dummy = {};
|
|
|
|
|
|
|
|
|
|
export function parseModel<T>(response: Response, json: UninitializedModel): T {
|
2022-09-15 08:13:33 +08:00
|
|
|
return (parseModelRecursively(response, dummy, '', json): any);
|
2020-11-03 10:49:48 +08:00
|
|
|
}
|
2023-04-22 11:45:51 +08:00
|
|
|
|
|
|
|
|
export function dispatchHint(code: string, model: mixed) {}
|