Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove outputTypeRegistry #191

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
node_modules
dist
.env
.vscode
15 changes: 7 additions & 8 deletions examples/chat-with-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ const folderId = getEnv('YC_FOLDER_ID');
const assistantId = assistant.id;
const threadId = thread.id;

await messageClient.create(
messageService.CreateMessageRequest.fromPartial({
threadId,
content: {
content: [{ text: { content: 'What is it "qwerty"?' } }],
},
}),
);
await messageClient.create({
labels: {},
threadId,
content: {
content: [{ text: { content: 'What is it "qwerty"?' } }],
},
});

const run = await runClient.create(
runService.CreateRunRequest.fromPartial({
Expand Down
109 changes: 55 additions & 54 deletions examples/compute-instance-create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
serviceClients, Session, cloudApi, waitForOperation, decodeMessage,
} from '@yandex-cloud/nodejs-sdk';
import { serviceClients, Session, cloudApi, waitForOperation } from '@yandex-cloud/nodejs-sdk';

import { Instance } from '@yandex-cloud/nodejs-sdk/compute-v1/instance';

import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

Expand All @@ -10,22 +11,12 @@ const TARGET_ZONE_ID = 'ru-central1-a';

const {
vpc: {
network_service: {
ListNetworksRequest,
ListNetworkSubnetsRequest,
},
network_service: { ListNetworksRequest, ListNetworkSubnetsRequest },
},
compute: {
image_service: {
GetImageLatestByFamilyRequest,
},
instance_service: {
CreateInstanceRequest,
DeleteInstanceRequest,
},
instance: {
IpVersion,
},
image_service: { GetImageLatestByFamilyRequest },
instance_service: { CreateInstanceRequest, DeleteInstanceRequest },
instance: { IpVersion },
},
} = cloudApi;

Expand All @@ -35,9 +26,11 @@ const {
const instanceClient = session.client(serviceClients.InstanceServiceClient);
const networkClient = session.client(serviceClients.NetworkServiceClient);

const networkResponse = await networkClient.list(ListNetworksRequest.fromPartial({
folderId: FOLDER_ID,
}));
const networkResponse = await networkClient.list(
ListNetworksRequest.fromPartial({
folderId: FOLDER_ID,
}),
);

log(`Found ${networkResponse.networks.length} networks in folder ${FOLDER_ID}`);

Expand All @@ -47,58 +40,66 @@ const {
throw new Error(`There are no networks in folder ${FOLDER_ID}`);
}

const subnetsResponse = await networkClient.listSubnets(ListNetworkSubnetsRequest.fromPartial({
networkId: network.id,
}));
const subnetsResponse = await networkClient.listSubnets(
ListNetworkSubnetsRequest.fromPartial({
networkId: network.id,
}),
);
const subnet = subnetsResponse.subnets.find((s) => s.zoneId === TARGET_ZONE_ID);

if (!subnet) {
throw new Error(`There is no subnet in zone ${TARGET_ZONE_ID} in folder ${FOLDER_ID}`);
}

const image = await imageClient.getLatestByFamily(GetImageLatestByFamilyRequest.fromPartial({
family: 'ubuntu-1804-lts',
folderId: 'standard-images',
}));

const createOp = await instanceClient.create(CreateInstanceRequest.fromPartial({
folderId: FOLDER_ID,
zoneId: TARGET_ZONE_ID,
platformId: 'standard-v2',
labels: { 'nodejs-sdk': 'yes' },
resourcesSpec: {
memory: 2 * 1024 * 1024 * 1024,
cores: 2,
},
bootDiskSpec: {
autoDelete: true,
diskSpec: {
size: 10 * 1024 * 1024 * 1024,
imageId: image.id,
const image = await imageClient.getLatestByFamily(
GetImageLatestByFamilyRequest.fromPartial({
family: 'ubuntu-1804-lts',
folderId: 'standard-images',
}),
);

const createOp = await instanceClient.create(
CreateInstanceRequest.fromPartial({
folderId: FOLDER_ID,
zoneId: TARGET_ZONE_ID,
platformId: 'standard-v2',
labels: { 'nodejs-sdk': 'yes' },
resourcesSpec: {
memory: 2 * 1024 * 1024 * 1024,
cores: 2,
},
},
networkInterfaceSpecs: [
{
subnetId: subnet.id,
primaryV4AddressSpec: {
oneToOneNatSpec: { ipVersion: IpVersion.IPV4 },
bootDiskSpec: {
autoDelete: true,
diskSpec: {
size: 10 * 1024 * 1024 * 1024,
imageId: image.id,
},
},
],
}));
networkInterfaceSpecs: [
{
subnetId: subnet.id,
primaryV4AddressSpec: {
oneToOneNatSpec: { ipVersion: IpVersion.IPV4 },
},
},
],
}),
);

log(`Instance create operation id: ${createOp.id}`);

const finishedCreateOp = await waitForOperation(createOp, session);

if (finishedCreateOp.response) {
const instance = decodeMessage<cloudApi.compute.instance.Instance>(finishedCreateOp.response);
const instance = Instance.decode(finishedCreateOp.response.value);

log(`Instance ${instance.id} created`);

const removeOp = await instanceClient.delete(DeleteInstanceRequest.fromPartial({
instanceId: instance.id,
}));
const removeOp = await instanceClient.delete(
DeleteInstanceRequest.fromPartial({
instanceId: instance.id,
}),
);

const finishedRemoveOp = await waitForOperation(removeOp, session);

Expand Down
7 changes: 1 addition & 6 deletions examples/generate-image-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ const folderId = getEnv('YC_FOLDER_ID');
generationOptions: {
mimeType: 'image/jpeg',
},
messages: [
imageGeneration.Message.fromPartial({
text: 'Three cats',
weight: 1,
}),
],
messages: [{ text: 'Three cats', weight: 1 }],
});

const imageGenerationResponse = await operationSdk.pollOperation(
Expand Down
45 changes: 26 additions & 19 deletions examples/kms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
serviceClients, Session, cloudApi, waitForOperation, decodeMessage,
} from '@yandex-cloud/nodejs-sdk';
import { serviceClients, Session, cloudApi, waitForOperation } from '@yandex-cloud/nodejs-sdk';
import { symmetricKey } from '@yandex-cloud/nodejs-sdk/kms-v1';
import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

Expand All @@ -19,32 +18,40 @@ const {
const keyClient = session.client(serviceClients.SymmetricKeyServiceClient);
const cryptoClient = session.client(serviceClients.SymmetricCryptoServiceClient);

const keyCreateOp = await keyClient.create(CreateSymmetricKeyRequest.fromPartial({
folderId,
defaultAlgorithm: SymmetricAlgorithm.AES_256,
}));
const keyCreateOp = await keyClient.create(
CreateSymmetricKeyRequest.fromPartial({
folderId,
defaultAlgorithm: SymmetricAlgorithm.AES_256,
}),
);
const finishedKeyCreateOp = await waitForOperation(keyCreateOp, session);

if (finishedKeyCreateOp.response) {
const key = decodeMessage<cloudApi.kms.symmetric_key.SymmetricKey>(finishedKeyCreateOp.response);
const key = symmetricKey.SymmetricKey.decode(finishedKeyCreateOp.response.value);

const encrypted = await cryptoClient.encrypt(SymmetricEncryptRequest.fromPartial({
keyId: key.id,
plaintext: Buffer.from('example message'),
}));
const encrypted = await cryptoClient.encrypt(
SymmetricEncryptRequest.fromPartial({
keyId: key.id,
plaintext: Buffer.from('example message'),
}),
);

log(`Got "${encrypted.ciphertext}" from KMS`);

const decrypted = await cryptoClient.decrypt(SymmetricDecryptRequest.fromPartial({
keyId: key.id,
ciphertext: encrypted.ciphertext,
}));
const decrypted = await cryptoClient.decrypt(
SymmetricDecryptRequest.fromPartial({
keyId: key.id,
ciphertext: encrypted.ciphertext,
}),
);

log(`Got "${decrypted.plaintext}" from KMS`);

const keyRemoveOp = await keyClient.delete(DeleteSymmetricKeyRequest.fromPartial({
keyId: key.id,
}));
const keyRemoveOp = await keyClient.delete(
DeleteSymmetricKeyRequest.fromPartial({
keyId: key.id,
}),
);

await waitForOperation(keyRemoveOp, session);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./node_modules/@yandex-cloud/nodejs-sdk/tsconfig.json",
"extends": "../tsconfig.json",
"include": ["./*.ts"]
}
4 changes: 3 additions & 1 deletion scripts/generate_services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ const generateCloudApi = () => {
const GENERATED_CODE_DIR = PATH.resolve('./src/generated');

const protoFiles = fg.sync('**/*.proto', { cwd: YA_PROTO_DIR, absolute: true });

const commandArgs = [
'npx --no-install grpc_tools_node_protoc',
`--ts_proto_out=${GENERATED_CODE_DIR}`,
'--ts_proto_opt=outputServices=grpc-js,esModuleInterop=true,outputTypeRegistry=true,env=node,useOptionals=messages',
'--ts_proto_opt=outputServices=grpc-js,esModuleInterop=true,env=node,useOptionals=messages',
`-I ${PROTO_DIR} -I ${PROTO_DIR}/third_party/googleapis`,
protoFiles.join(' '),
];

const command = commandArgs.join(' ');

return exec(command);
Expand Down
29 changes: 5 additions & 24 deletions src/generated/google/api/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable */
import { messageTypeRegistry } from '../../typeRegistry';
import Long from 'long';
import _m0 from 'protobufjs/minimal';

Expand All @@ -11,7 +10,6 @@ export const protobufPackage = 'google.api';
* to one or more HTTP REST API methods.
*/
export interface Http {
$type: 'google.api.Http';
/**
* A list of HTTP configuration rules that apply to individual API methods.
*
Expand Down Expand Up @@ -229,7 +227,6 @@ export interface Http {
* content to Web (HTML) clients.
*/
export interface HttpRule {
$type: 'google.api.HttpRule';
/**
* Selects methods to which this rule applies.
*
Expand Down Expand Up @@ -265,18 +262,15 @@ export interface HttpRule {

/** A custom pattern is used for defining custom HTTP verb. */
export interface CustomHttpPattern {
$type: 'google.api.CustomHttpPattern';
/** The name of this custom HTTP verb. */
kind: string;
/** The path matched by this custom verb. */
path: string;
}

const baseHttp: object = { $type: 'google.api.Http' };
const baseHttp: object = {};

export const Http = {
$type: 'google.api.Http' as const,

encode(message: Http, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.rules) {
HttpRule.encode(v!, writer.uint32(10).fork()).ldelim();
Expand Down Expand Up @@ -326,13 +320,9 @@ export const Http = {
},
};

messageTypeRegistry.set(Http.$type, Http);

const baseHttpRule: object = { $type: 'google.api.HttpRule', selector: '', body: '' };
const baseHttpRule: object = { selector: '', body: '' };

export const HttpRule = {
$type: 'google.api.HttpRule' as const,

encode(message: HttpRule, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.selector !== '') {
writer.uint32(10).string(message.selector);
Expand Down Expand Up @@ -476,13 +466,9 @@ export const HttpRule = {
},
};

messageTypeRegistry.set(HttpRule.$type, HttpRule);

const baseCustomHttpPattern: object = { $type: 'google.api.CustomHttpPattern', kind: '', path: '' };
const baseCustomHttpPattern: object = { kind: '', path: '' };

export const CustomHttpPattern = {
$type: 'google.api.CustomHttpPattern' as const,

encode(message: CustomHttpPattern, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.kind !== '') {
writer.uint32(10).string(message.kind);
Expand Down Expand Up @@ -536,8 +522,6 @@ export const CustomHttpPattern = {
},
};

messageTypeRegistry.set(CustomHttpPattern.$type, CustomHttpPattern);

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin
Expand All @@ -547,16 +531,13 @@ export type DeepPartial<T> = T extends Builtin
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in Exclude<keyof T, '$type'>]?: DeepPartial<T[K]> }
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P> | '$type'>,
never
>;
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
Expand Down
Loading
Loading